First of all, this is NOT the frequently-posted problem where the result code is returned prematurely. In this case, it is returned only after an item is picked in the gallery.
In my test case I call the Gallery with this code:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, SELECT_PICTURE);
and in onActivityResult there is:
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
pathText.setText(selectedImageUri.getPath());
}
} else {
pathText.setText("Result not OK - code is " + resultCode);
}
pathText is just a TextView I put in to show the result in the test case. In the actual application there is a different use for the path.
If I use ACTION_PICK instead of _GET_CONTENT I get the immediate failure reported by others. There are no launchMode tags in the manifest (some posts have suggested problems in that area).
Maybe there is a clue here. On a Toshiba Thrive, this bug does not appear, using Gallery, File Manager, or Fish Bowl Photo Gallery. On Kindle Fire, Quickoffice is also able to return an image path correctly. The bug only appears for me on the Kindle's built-in Gallery. The bug was also observed on a "Motorola Droid(2.3.4) , HTC EVO (2.3)".
Please, how can I get an image path back from the Gallery in a way that works on all these devices?
I think, by default gallery does not return result code if you not specify in the intent to return result code. You can specify in the intent to return result code by adding this snippet in your code like this:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true); //added snippet
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_PICTURE);
I was having same problem in one of my activities when I set launchMode="singleInstance" in manifest for that activity. It works fine when I remove that attribute.
Hi Steve try this seems to work on my wallpaper project
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_PICTURE);