简体   繁体   中英

Button to start the Gallery on Android

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM