Cha*_*lot 4 java pdf android android-intent
我想宣传我的应用程序能够查看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>
Run Code Online (Sandbox Code Playgroud)
每当我从文件管理器打开pdf时,它会自动选择另一个名为Polaris Viewer的pdf应用程序.
我在应用程序设置下检查以确保Polaris不是默认应用程序.它说没有设置默认值.
此外,我下载了一个名为Intent Intercept的第三方应用程序.如果我从文件管理器中选择一个pdf文件,则会出现一个应用程序选择器,显示Polaris和Intent Intercept.如果我选择Intent Intercept,它会告诉我Polaris和我的app(Rollout PdfEditor)都符合意图.这是Intent Interceptor的输出:
动作:android.intent.action.VIEW
DATA:file:///storage/sdcard0/Download/download.pdf TYPE:application/pdf
标志:FLAG_ACTIVITY_FORWARD_RESULT FLAG_ACTIVITY_PREVIOUS_IS_TOP
EXTRAS:EXTRA 1:Class:java.lang.Boolean Key:preview Value:false EXTRA 2:Class:java.lang.String Key:key_filename Value:/storage/sdcard0/Download/download.pdf EXTRA 3:Class:android. net.Uri $ HierarchicalUri Key:android.intent.extra.STREAM EXTRA 4:Class:java.lang.Integer Key:sort_order Value:0
2活动与此目标相匹配:Polaris Viewer 4.1(com.infraware.polarisviewer4 - com.infraware.polarisoffice4.OfficeLauncherActivity)Rollout PdfEditor(com.example.rolloutpdfeditor - com.example.rolloutpdfeditor.MainActivity)>
您缺少必需的<category />标签IntentFilter!如果你看一下<category />它的文档说:
注意:要接收隐式意图,必须在intent过滤器中包含CATEGORY_DEFAULT类别.方法startActivity()和startActivityForResult()将所有意图视为已声明CATEGORY_DEFAULT类别.如果您未在意图过滤器中声明它,则不会将隐式意图解析为您的活动.
因此,您必须始终将其android.intent.category.DEFAULT作为IntentFilter工作类别包含在内.如果您希望应用程序能够处理来自浏览器或其他应用程序的pdf链接,您还需要包括android.intent.category.BROWSABLE.你可以BROWSABLE 在这里找到相关文档.它写道:
CATEGORY_BROWSABLE
目标活动允许自己由Web浏览器启动,以显示链接引用的数据 - 例如图像或电子邮件.
试试这个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>
Run Code Online (Sandbox Code Playgroud)
我想你错过了这两个类别.
| 归档时间: |
|
| 查看次数: |
1625 次 |
| 最近记录: |