美文网首页
Android 11无法使用queryIntentActivit

Android 11无法使用queryIntentActivit

作者: Dapengyou | 来源:发表于2023-01-30 23:58 被阅读0次

Android 11 以后使用 queryIntentActivities 查询获取到的值很大程度上是 Empty 的,因为 Android 11 以后只开放一些自动对您的应用可见的应用如:浏览器、apk安装等,其他应用查不到了。

解决这个问题的方法有两种:

  1. 在 Manifest 中添加 QUERY_ALL_PACKAGES 权限

但同样的这个权限在谷歌属于敏感信息权限,如果想上架谷歌应用商店,不建议这么做

  1. 在 Manifest 中添加 <queries> 标签

在谷歌文档的根据用例配置软件包可见性里的打开文件里有介绍用法

<!-- Place inside the <queries> element. -->
<intent>
  <action android:name="android.intent.action.VIEW" />
  <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". -->
  <data android:mimeType="application/pdf" />
</intent>

如果是查看图片可以更换成:

<intent>
  <action android:name="android.intent.action.VIEW" />
  <data android:mimeType="image/*" />
</intent>

如果不知道 mime 的类型,可以写成:

<intent>
  <action android:name="android.intent.action.VIEW" />
  <data android:mimeType="*/*" />
</intent>

还可以参考文档管理软件包可见性

相关文章

网友评论

      本文标题:Android 11无法使用queryIntentActivit

      本文链接:https://www.haomeiwen.com/subject/abevhdtx.html