Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The data associated with your returned Intent is not a bitmap. It's a URI you can use to look up in the MediaStore ContentProvider to get back the image you want. :)</p> <p>You can find a mostly-working example over at <a href="https://stackoverflow.com/questions/3680357/how-to-query-android-mediastore-content-provider-avoiding-orphaned-images">this question</a>.</p> <p><strong>Edit</strong>: To expand:</p> <p>When you go off and query the <code>MediaStore</code> for an image, it isn't returning you the actual image. It's returning you a URI that you can use to look up the image. The way you translate that URI into an actual image is this:</p> <p>Your URI is <code>content://media/external/images/media/2</code> as per the error message.</p> <p>So, we'll basically create a query and run it on the <code>MediaStore</code>'s <code>ContentProvider</code>, which is a database of images. Pass that URI into this function:</p> <pre><code>public Bitmap loadFullImage( Context context, Uri photoUri ) { Cursor photoCursor = null; try { // Attempt to fetch asset filename for image // DATA is the column name in the database for the filename of the image String[] projection = { MediaStore.Images.Media.DATA }; // use the URI you were given in order to look up the right image, // and get a Cursor object that will iterate over the matching rows in the // database. photoCursor = context.getContentResolver().query( photoUri, projection, null, null, null ); // since we only care about one image... if ( photoCursor != null &amp;&amp; photoCursor.getCount() == 1 ) { // go to the first row that was returned photoCursor.moveToFirst(); // get the string in the DATA column at that row String photoFilePath = photoCursor.getString( photoCursor.getColumnIndex(MediaStore.Images.Media.DATA) ); // Load image from path return BitmapFactory.decodeFile( photoFilePath, null ); } } finally { // close up the cursor if ( photoCursor != null ) { photoCursor.close(); } } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload