我想宣传我的应用程序能够查看pdf文件,这样当从文件管理器中选择pdf文件时,它就会出现在应用程序选择器中。
这是我的意图过滤器的外观
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/pdf" />
</intent-filter>
</activity>
每当我从文件管理器打开pdf时,它都会自动选择另一个名为Polaris Viewer的pdf应用程序。
我检查以确保Polaris不是应用程序设置下的默认应用程序。它说没有默认设置。
另外,我下载了一个名为Intent Intercept的第三方应用程序。如果我从文件管理器中选择一个pdf文件,则会出现一个应用选择器,显示Polaris和Intent Intercept。如果我选择“意图拦截”,它会告诉我Polaris和我的应用程序(“ Rollout PdfEditor”)都符合该意图。这是Intent Interceptor的输出:
动作:android.intent.action.VIEW
数据:file:///storage/sdcard0/Download/download.pdf类型:应用程序/ pdf
旗帜:FLAG_ACTIVITY_FORWARD_RESULT FLAG_ACTIVITY_PREVIOUS_IS_TOP
EXTRAS:EXTRA 1:类:java.lang.Boolean键:预览值:false EXTRA 2:类:java.lang.String键:key_filename值:/storage/sdcard0/Download/download.pdf EXTRA 3:类:android。 net.Uri $ HierarchicalUri键:android.intent.extra.STREAM EXTRA 4:类:java.lang.Integer键:sort_order值:0
2个活动匹配此意图:Polaris Viewer 4.1(com.infraware.polarisviewer4-com.infraware.polarisoffice4.OfficeLauncherActivity)推出PdfEditor(com.example.rolloutpdfeditor-com.example.rolloutpdfeditor.MainActivity)>
您缺少必填<category />
标签IntentFilter
!如果您查看文档<category />
说明:
注意:为了接收隐式意图,必须在意图过滤器中包括CATEGORY_DEFAULT类别。方法startActivity()和startActivityForResult()将所有意图都视为声明了CATEGORY_DEFAULT类别。如果您没有在意图过滤器中声明它,则任何隐式意图都不会解析您的活动。
因此,您必须始终将android.intent.category.DEFAULT
类别包括在内IntentFilter
才能使用。如果您希望应用程序能够处理来自浏览器或其他应用程序的pdf链接,则还需要包含android.intent.category.BROWSABLE
。您可以BROWSABLE
在此处找到文档。内容为:
CATEGORY_BROWSABLE
目标活动允许它由网络浏览器启动,以显示链接引用的数据-例如图像或电子邮件。
试试这个IntentFilter
:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
我认为您缺少这两个类别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句