Button to start the Gallery on Android

人盡茶涼 提交于 2019-12-25 03:09:02

问题


I'm trying to make a button in my App open the built in gallery.

public void onClick(View v) {
                Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
                intentBrowseFiles.setType("image/*");
                intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intentBrowseFiles);                   
            }

This results in an error message "The application Camera (process com.android.gallery) has stopped unexpectedly."

If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.


回答1:


I'm trying to make a button in my App open the built in browser.

Your question subject says "Gallery". Your first sentence in the question says "browser". These are not the same thing.

If I set the Intent action to ACTION_GET_CONTENT it manages to open the gallery but then simply returns the image to my app when a picture is selected which is not what I want.

Of course, actually telling us "what [you] want" would just be too useful, so you are making us guess.

I am going to go out on a limb and guess that you are trying to open the Gallery application just as a normal application. Note that there is no Gallery application in the Android OS. There may or may not be a Gallery application on any given device, and it may or may not be one from the Android open source project.

However, for devices that have the Android Market on them, they should support an ACTION_VIEW Intent with a MIME type obtained from android.provider.MediaStore.Images.Media.CONTENT_TYPE.



来源:https://stackoverflow.com/questions/4979075/button-to-start-the-gallery-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!