Unable to select specific images using ACTION_PICK intent

I use this intention:

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); 

And in onActivityResult() I have this:

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != Activity.RESULT_OK) { return; // user cancelled } Uri imageUri = data.getData(); if (imageUri == null) { // (code to show error message goes here) return; } // Get image path from media store String[] filePathColumn = { android.provider.MediaStore.MediaColumns.DATA }; Cursor cursor = this.getContentResolver().query(imageUri, filePathColumn, null, null, null); if (cursor == null || !cursor.moveToFirst()) { // (code to show error message goes here) return; } int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String imagePath = cursor.getString(columnIndex); cursor.close(); if (imagePath == null) { // error happens here } } 

When I select images from certain albums, such as Messages, Profile Photos (see screenshot), I cannot get the image path in onActivityResult() . Images from other albums can be selected without problems.

Galley screenshot

I tried adding intent.putExtra("return-data", true) , but data.getExtras() returns null in onActivityResult() .

There is a similar question here , but no one answered it.

Please, help!

+2
android android-intent
Mar 08 '13 at 0:29
source share
2 answers

hops this will help you ....

ACTIVITYRESULT_CHOOSEPICTURE is the int that you use when calling startActivity (intent, requestCode);

 public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) { BitmapFactory.Options options = new BitmapFactory.Options(); final InputStream ist = ontext.getContentResolver().openInputStream(intent.getData()); final Bitmap bitmap = BitmapFactory.decodeStream(ist, null, options); ist.close(); } } 

if the above code doesn’t work, than just linking to this link ... this will depressingly show a way

http://dimitar.me/how-to-get-picasa-images-using-the-image-picker-on-android-devices-running-any-os-version/

+6
Mar 08 '13 at 6:28
source share

try the following:

 String selectedImagePath = imageUri.getEncodedPath(); 

it works for me using gallery image picker

perhaps it:

 bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), data.getData()); 
+1
Mar 08 '13 at 0:36
source share



All Articles