开发者

Pick an image from the Gallery

开发者 https://www.devze.com 2022-12-29 19:30 出处:网络
I have seen a lot of posts about this, and it seems like the code below should work.I have created an SD Card image and added it to the emulator (and that works f开发者_StackOverflow社区ine).

I have seen a lot of posts about this, and it seems like the code below should work. I have created an SD Card image and added it to the emulator (and that works f开发者_StackOverflow社区ine).

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

It does launch and allow selection of images, but when I click on an image, everything exits and the emulator returns to the home screen, not the back to my app. My onActivityResult is never called either.

What am I missing?


I found my issue. I was launching the gallery from a sub-activity and that sub activity Intent had the flag FLAG_ACTIVITY_NO_HISTORY which prevented the call back from going to that activity.

thanks.


Use the following intent :

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

精彩评论

暂无评论...
验证码 换一张
取 消