Select image from gallery

I've seen many posts about this and it seems like the code below should work. I created an SD card image and added it to the emulator (and this works great).

        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        //intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intent, 1);

      

It launches and allows the selection of images, but when I click on the image everything exits and the emulator goes back to the main screen, not back to my application. My onActivityResult is never called.

What am I missing?

+2


a source to share


2 answers


I found my problem. I was launching the gallery from a sub-task and that Intent had a FLAG_ACTIVITY_NO_HISTORY flag that prevented the callback from navigating to that activity.



thanks.

+2


a source


Use the following assignment:



        Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
        intent.setType("image/*");
        intent.putExtra("return-data", true);
        startActivityForResult(intent, 1);

      

0


a source







All Articles