Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

android - Unable to select particular images using ACTION_PICK intent

I'm using an intent like this:

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 particular albums like "Posts", "Profile Photos" (see screenshot) I'm unable to get the image path in onActivityResult(). Images from other albums can be selected with no problems.

Galley screenshot

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

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

Please help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

hops this will helps you ....

ACTIVITYRESULT_CHOOSEPICTURE is the int 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 above code doesn't work than just refer this link... it will surly shows the way

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...