java - Android:检查是否存在可以打开 xps 文件的应用程序

标签 java android android-intent

我有一个应用程序需要打开一个 XPS 文件。 我可以使用下面的代码触发 Intent 打开文件,但是我想知道是否有办法检查手机上是否有任何应用程序可以处理打开此文件的请求文件。

我的想法是,如果手机上没有任何应用程序可以打开 XPS 文件,我可以提示用户下载一个应用程序来打开 XPS 文件。

    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(fileURL.toURI());
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.ms-xpsdocument");
    //intent.setDataAndType(Uri.fromFile(file), "application/*");
    startActivity(intent); 

有什么想法吗?

最佳答案

我从未使用过它,但我认为您可以使用 PackageManager.queryIntentActivities(...) 来完成此操作

创建 Intent您通常会使用它来打开 XPS 文件并调用该方法。如果返回List<ResolveInfo>为空则没有注册处理 XPS 文件的 Activity 。

关于java - Android:检查是否存在可以打开 xps 文件的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8810011/

相关文章:

java - Java Bitset 类与 Byte 数组的比较 - Byte 数组相对于 Bitset 类的优点

android - 服务器收到订阅状态更改通知时如何识别用户

python - 在 Android 上使用 bash shell 打开浏览器后尝试输入搜索数据

java - 尝试创建新的 JarFile 时出现 "java.util.zip.ZipException: error in opening zip file"

java - 对源代码的编译后自定义操作?

java - 事务中读取的每个文档也必须写入 : Firestore Transaction Exception in android

android - Android 上的 YouTubePlayerFragment 不显示广告 - YouTube Android Player API

android - 太多的 XML 数据绑定(bind)

android - 无法获得隐含的 Intent 来工作

android - 如何获取日期、小时、分钟以达到特定日期