【问题标题】:Android Intent choose set default appAndroid Intent 选择设置默认应用
【发布时间】:2014-05-18 05:41:43
【问题描述】:

我正在开发一个 android 应用程序,当用户单击链接和/或文件时,我想让他们选择要使用哪个应用程序来打开该链接和/或文件。目前它按预期的方式工作,但我无法尝试让用户选择一个复选框,让他们选择默认应用程序来打开该文件,这样他们就不必每次都选择它。我正在考虑在对话框中设置一个复选框,然后将其值与应用程序选择一起提交给共享首选项。之后,每次他们单击该文件时,都会打开默认应用程序。本质上,我正在尝试获得一个像这样的对话框,

但我一直得到这个,

代码如下:

Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, mimeChoice);
startActivity(Intent.createChooser(intent,getActivity().getString(R.string.open_with_title)));

【问题讨论】:

  • 您通常不必创建此对话框,除非您需要非常具体的内容。 Android 操作系统将根据您构建的 Intent 处理此问题。

标签: java android android-intent filechooser


【解决方案1】:

就像 tambykojak 指出的那样,“Android 操作系统会根据你构建的 Intent 来处理这个问题”,并且没有默认应用程序的选项。但是您将通过获取由包确定的安装的应用程序来构建自己的自定义对话框: 例如:

Facebook:“com.facebook.katana”; Whatsapp:“com.whatsapp”; 推特:“com.twitter.android”; Google Playstore:“com.android.vending”; Chrome:“com.android.chrome”等...

并在首选项中保存“默认”选项。

更多信息:

How to force Share Intent to open a specific app?

How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

【讨论】:

    猜你喜欢
    • 2019-12-19
    • 2015-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多