简体   繁体   English

在Android上启动图库的按钮

[英]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." 这将导致错误消息“应用程序Camera(进程com.android.gallery)已意外停止”。

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. 如果我将Intent动作设置为ACTION_GET_CONTENT,则它可以打开画廊,但是当选择的图片不是我想要的时,只需将图片返回到我的应用即可。

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. 如果我将Intent动作设置为ACTION_GET_CONTENT,则它可以打开画廊,但是当选择的图片不是我想要的时,只需将图片返回到我的应用即可。

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. 我将不知所措,猜想您正在尝试像正常应用程序一样打开Gallery应用程序。 Note that there is no Gallery application in the Android OS. 请注意,Android操作系统中没有Gallery应用程序。 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. 在任何给定的设备上可能存在或可能没有Gallery应用程序,并且它可能不是Android开放源代码项目中的一个。

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 . 但是,对于带有Android Market的设备,它们应支持ACTION_VIEW Intent ,其MIME类型可从android.provider.MediaStore.Images.Media.CONTENT_TYPE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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