Intent.ACTION_PICK的行为有所不同 [英] Intent.ACTION_PICK behaves differently

查看:98
本文介绍了Intent.ACTION_PICK的行为有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从图库中选取图片.当我用Samsung Galaxy S4测试它时,它直接转到了我实际想要的Gallery.

I am using following code to pick an image from the gallery. When I test it with Samsung Galaxy S4, it directly goes to Gallery that is what I want actually.

但是,当我在LG Optimus II设备上测试我的代码时,它显示一个对话框,提供选择图库或图片的选项.换句话说,它增加了我不想要的另一层.

BUT, when I test my code on LG Optimus II device, it shows a dialog gives an option to choose either Gallery or Picture. In other words, it adds one more layer which I do not want.

两个设备都具有KitKat 4.4.2操作系统.

Both devices have KitKat 4.4.2 operating system.

public static void showFileChooser(Activity activity) {
  Intent intent = new Intent();
  intent.setType("image/*");
  intent.setAction(Intent.ACTION_PICK);
  activity.startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
}

推荐答案

当我在LG Optimus II设备上测试我的代码时,它显示一个对话框,提供选择图库或图片的选项

when I test my code on LG Optimus II device, it shows a dialog gives an option to choose either Gallery or Picture

这是因为该设备上有两个活动支持image/*文件的ACTION_PICK.此类活动的数量可以为零到N,具体取决于设备上的应用程序.这将包括预安装的应用程序和用户自行安装的应用程序.这些范围从本地文件管理器到一般的云提供商(例如Dropbox)再到图像特定的应用程序(例如Instagram).

That is because there are two activities on that device that support ACTION_PICK of image/* files. There can be zero to N such activities, depending on what apps are on the device. This will include both pre-installed apps and apps that the user installed themselves. These will range from local file managers to general cloud providers (e.g., Dropbox) to image-specific apps (e.g., Instagram).

换句话说,它又增加了我不想要的一层.

In other words, it adds one more layer which I do not want.

然后不使用ACTION_PICK.您正在委托第三方应用程序;用户希望使用哪个第三方应用程序,取决于用户,而不是您.

Then do not use ACTION_PICK. You are delegating to a third-party app; it is up to the user, not you, what third-party app the user wishes to use.

这篇关于Intent.ACTION_PICK的行为有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆