snipt

Ctrl+h for KB shortcuts

Java

Show an image with built in viewer

1
2
3
4
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(YOUR_IMAGE_FILE)), "image/jpg");
startActivity(intent);			
https://snippets.siftie.com/embed/a5a798cf6df8b4836fc40700622d6312/
/raw/a5a798cf6df8b4836fc40700622d6312/
a5a798cf6df8b4836fc40700622d6312
java
Java
5
2019-03-05T10:40:01
True
False
False
/api/public/snipt/19048/
show-an-image-with-built-in-viewer
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">Intent</span> <span class="n">intent</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Intent</span><span class="o">();</span> </span><span id="L-2"><a name="L-2"></a><span class="n">intent</span><span class="o">.</span><span class="na">setAction</span><span class="o">(</span><span class="n">android</span><span class="o">.</span><span class="na">content</span><span class="o">.</span><span class="na">Intent</span><span class="o">.</span><span class="na">ACTION_VIEW</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a><span class="n">intent</span><span class="o">.</span><span class="na">setDataAndType</span><span class="o">(</span><span class="n">Uri</span><span class="o">.</span><span class="na">fromFile</span><span class="o">(</span><span class="k">new</span> <span class="n">File</span><span class="o">(</span><span class="n">YOUR_IMAGE_FILE</span><span class="o">)),</span> <span class="s">&quot;image/jpg&quot;</span><span class="o">);</span> </span><span id="L-4"><a name="L-4"></a><span class="n">startActivity</span><span class="o">(</span><span class="n">intent</span><span class="o">);</span> </span></pre></div> </td></tr></table>
android