简体   繁体   English

如何让我的应用程序出现在app chooser中?

[英]How do I make my app appear in app chooser?

I want to advertise that my app is capable of viewing pdf files so that it will appear in the app chooser when a pdf file is selected from the file manager. 我想宣传我的应用程序能够查看pdf文件,以便在从文件管理器中选择pdf文件时它将显示在应用程序选择器中。

Here is what my intent filters look like 这是我的意图过滤器的样子

<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>

Whenever I open a pdf from file manager it automatically selects another pdf app called Polaris Viewer. 每当我从文件管理器打开pdf时,它会自动选择另一个名为Polaris Viewer的pdf应用程序。

I checked to make sure that Polaris is not the default app, under application settings. 我在应用程序设置下检查以确保Polaris不是默认应用程序。 It says no defaults set. 它说没有设置默认值。

Also, I downloaded an third party app called Intent Intercept. 此外,我下载了一个名为Intent Intercept的第三方应用程序。 If I select a pdf file from file manager an app chooser appears showing Polaris and Intent Intercept. 如果我从文件管理器中选择一个pdf文件,则会出现一个应用程序选择器,显示Polaris和Intent Intercept。 If I choose Intent Intercept it tells me that both Polaris and my app (Rollout PdfEditor) match the intent. 如果我选择Intent Intercept,它会告诉我Polaris和我的app(Rollout PdfEditor)都符合意图。 Here is the output from Intent Interceptor: 这是Intent Interceptor的输出:

ACTION: android.intent.action.VIEW 动作:android.intent.action.VIEW

DATA: file:///storage/sdcard0/Download/download.pdf TYPE: application/pdf DATA:file:///storage/sdcard0/Download/download.pdf TYPE:application / pdf

FLAGS: FLAG_ACTIVITY_FORWARD_RESULT FLAG_ACTIVITY_PREVIOUS_IS_TOP 标志: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 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 ACTIVITIES MATCH THIS INTENT: Polaris Viewer 4.1 (com.infraware.polarisviewer4 - com.infraware.polarisoffice4.OfficeLauncherActivity) Rollout PdfEditor (com.example.rolloutpdfeditor - com.example.rolloutpdfeditor.MainActivity) > 2活动与此目标相匹配:Polaris Viewer 4.1(com.infraware.polarisviewer4 - com.infraware.polarisoffice4.OfficeLauncherActivity)Rollout PdfEditor(com.example.rolloutpdfeditor - com.example.rolloutpdfeditor.MainActivity)>

You are missing required <category /> tags from your IntentFilter ! 您缺少IntentFilter必需的<category />标签! if you look at the documentation for <category /> it says: 如果你看一下<category />的文档,它会说:

Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. 注意:要接收隐式意图,必须在intent过滤器中包含CATEGORY_DEFAULT类别。 The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. 方法startActivity()和startActivityForResult()将所有意图视为已声明CATEGORY_DEFAULT类别。 If you do not declare it in your intent filter, no implicit intents will resolve to your activity. 如果您未在意图过滤器中声明它,则不会将隐式意图解析为您的活动。

So you always have to include android.intent.category.DEFAULT as category for the IntentFilter to work at all. 所以你总是必须包含android.intent.category.DEFAULT作为IntentFilter类别才能工作。 If you want you app to be able to handle pdf links from a browser or other apps you also need to include android.intent.category.BROWSABLE . 如果您希望应用程序能够处理来自浏览器或其他应用程序的pdf链接,您还需要包含android.intent.category.BROWSABLE You can find documentation about BROWSABLE here . 您可以在此处找到有关BROWSABLE文档。 It reads: 它写道:

CATEGORY_BROWSABLE CATEGORY_BROWSABLE
The target activity allows itself to be started by a web browser to display data referenced by a link — such as an image or an e-mail message. 目标活动允许自己由Web浏览器启动,以显示链接引用的数据 - 例如图像或电子邮件。

Try this IntentFilter : 试试这个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>

I think you are missing those two categories. 我想你错过了这两个类别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM