<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[MediaStore - JBay Solutions - The Dev Blog]]></title><description><![CDATA[JBay Solutions Development Blog on Java, Android, Play2 and others]]></description><link>http://blog.jbaysolutions.com/</link><generator>Ghost 0.7</generator><lastBuildDate>Wed, 16 Oct 2024 01:15:05 GMT</lastBuildDate><atom:link href="http://blog.jbaysolutions.com/tag/mediastore/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Accessing Images in Android External Storage]]></title><description><![CDATA[<p>To access the list of media files (such as Audio, Images and Video) from an External Storage device in android, the Media provider can be used.</p>

<p>An example of using the Media provider to access all Image type files on the External Storage:</p>

<pre><code>Cursor mCursor = getContentResolver()
        .query(
            MediaStore.Images.Media.</code></pre>]]></description><link>http://blog.jbaysolutions.com/2015/10/15/accessing-images-in-android-external-memory/</link><guid isPermaLink="false">2d360f0c-6998-4e92-af9d-e42be6687bfa</guid><category><![CDATA[android]]></category><category><![CDATA[MediaStore]]></category><dc:creator><![CDATA[Rui Pereira]]></dc:creator><pubDate>Thu, 15 Oct 2015 09:37:05 GMT</pubDate><content:encoded><![CDATA[<p>To access the list of media files (such as Audio, Images and Video) from an External Storage device in android, the Media provider can be used.</p>

<p>An example of using the Media provider to access all Image type files on the External Storage:</p>

<pre><code>Cursor mCursor = getContentResolver()
        .query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            null,
            null, 
            null,
            MediaStore.Images.Media.DEFAULT_SORT_ORDER);
</code></pre>

<p>Then we can go through the cursos and get all sorts of data from each existing image:</p>

<pre><code>mCursor.moveToFirst();
    while(!mCursor.isAfterLast()) {
        Log.d(TAG, " - _ID : " + mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media._ID)));
        Log.d(TAG, " - File Name : " + mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME)));
        Log.d(TAG, " - File Path : " + mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA)));
        mCursor.moveToNext();
    }
    mCursor.close();
</code></pre>

<p>In the previous example:</p>

<ul>
<li><code>MediaStore.Images.Media.DISPLAY_NAME</code>: is the name of the file.</li>
<li><code>MediaStore.Images.Media.DATA</code>: is the full Path of the file.</li>
</ul>

<p>Each image has an ID associated with it, which can be used to  for eample getting the thumbnail of that image: <code>MediaStore.Images.Media._ID</code></p>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h1 id="gettingthumbnailfrommediaprovider">Getting Thumbnail from Media provider</h1>

<p>The Media provider also provides access to two types of auto generated Thumbnails for the images:</p>

<ul>
<li>MINI_KIND: 512 x 384 </li>
<li>MICRO_KIND: 96 x 96</li>
</ul>

<p>Keep in mind that an image in the Media store might also not have thumbnails.</p>

<pre><code>mCursor = context.getContentResolver()
        .query(
                    MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                    null,
                    MediaStore.Images.Thumbnails.IMAGE_ID + "=?" ,
                    new String[]{id}, 
                    null);
</code></pre>

<p>Where id is the value of <code>MediaStore.Images.Media._ID</code> of the particular Image in question.</p>

<p>The following code prints a list of the available thumbnails for a specific image:</p>

<pre><code>mCursor.moveToFirst();
while (!mCursor.isAfterLast()){
    Log.d(TAG, "  - Thumbnail File Path : " + mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
    Log.d(TAG, "  - Thumbnail Type : " + mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Thumbnails.KIND));
    mCursor.moveToNext();
}
mCursor.close();
</code></pre>

<p>Where Thumbnail Kind is an integer:</p>

<ul>
<li><code>MediaStore.Images.Thumbnails.MICRO_KIND</code>: 3</li>
<li><code>MediaStore.Images.Thumbnails.MINI_KIND</code> : 1</li>
</ul>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h3 id="furtherreading">Further reading</h3>

<p><a href="http://developer.android.com/intl/zh-tw/reference/android/provider/MediaStore.html">Android API reference for Media provider</a></p>

<p><a href="http://developer.android.com/intl/zh-tw/reference/android/provider/MediaStore.MediaColumns.html">Media Columns List</a></p>

<p><a href="http://developer.android.com/intl/zh-tw/reference/android/provider/MediaStore.Images.ImageColumns.html">Extra Image Specific Columns List</a></p>]]></content:encoded></item></channel></rss>