如何让我的应用程序出现在应用程序选择器? [英] How do I make my app appear in app chooser?

查看:270
本文介绍了如何让我的应用程序出现在应用程序选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要宣传,当从文件管理器中选择一个PDF文件,我的应用程序能够查看PDF文件,以便它会出现在应用程序选择器。

下面是我的意图过滤器看起来像

 <活动
    机器人:名字=。MainActivity
    机器人:标签=@字符串/ APP_NAME>
    &所述;意图滤光器>
        <作用机器人:名字=android.intent.action.MAIN/>
        <类机器人:名字=android.intent.category.LAUNCHER/>
    &所述; /意图滤光器>
    &所述;意图滤光器>
        <作用机器人:名字=android.intent.action.VIEW/>
        <数据机器人:mime类型=应用/ PDF/>
    &所述; /意图滤光器>
< /活性GT;

每当我打开一个PDF从文件管理器,它会自动选择叫宝来查看其它PDF应用程序。

我检查,以确保北极星不是默认的应用程序,在应用程序设置。它说,没有默认设置。

另外,我下载了所谓的意图拦截的第三方应用程序。如果我从文件管理器中选择一个PDF文件的应用程序选择器出现显示北极星和意图拦截。如果让我选择意向拦截它告诉我,无论宝来和我的应用程序(分装PdfEditor)符合目的。下面是从意图拦截器的输出:


  

ACTION:android.intent.action.VIEW


  
  

DATA:文件:///storage/sdcard0/Download/download.pdf
  类型:application / PDF


  
  

标志:
        FLAG_ACTIVITY_FORWARD_RESULT
        FLAG_ACTIVITY_ preVIOUS_IS_TOP


  
  

附加功能:
  EXTRA 1:
  类别:java.lang.Boolean的
  重点:preVIEW
  值:假
  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的活动符合这个意图:
  宝来4.1浏览器(com.infraware.polarisviewer4 - com.infraware.polarisoffice4.OfficeLauncherActivity)
  部署PdfEditor(com.example.rolloutpdfeditor - com.example.rolloutpdfeditor.MainActivity)>



解决方案

您缺少必需的<类/> 的IntentFilter标记!如果你看一下文档<类/> 它说:


  

请注意:为了获得隐含的意图,你必须包括
  在意图过滤CATEGORY_DEFAULT类别。该方法
  startActivity()和startActivityForResult()把所有的意图,如果
  他们宣布CATEGORY_DEFAULT类别。如果你不把它声明
  在你的意图过滤器,没有隐含意图将解决你的
  活动。


所以,你总是必须包括 android.intent.category.DEFAULT 作为类为的IntentFilter 在工作所有。如果您希望应用能够处理从浏览器或其他应用程序,你还需要包括 android.intent.category.BROWSABLE PDF链接。你可以找到关于 BROWSABLE 这里 。它读取:


  

CATEGORY_BROWSABLE 结果
  目标活动允许自己通过Web浏览器来显示一个链接引用数据启动 - 如图像或电子邮件


试试这个的IntentFilter

 <意向滤光器>
    <作用机器人:名字=android.intent.action.VIEW/>
    <类机器人:名字=android.intent.category.BROWSABLE/>
    <类机器人:名字=android.intent.category.DEFAULT/>
    <数据机器人:mime类型=应用/ PDF/>
&所述; /意图滤光器>

我认为你缺少这两个类别。

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.

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.

I checked to make sure that Polaris is not the default app, under application settings. It says no defaults set.

Also, I downloaded an third party app called Intent Intercept. If I select a pdf file from file manager an app chooser appears showing Polaris and Intent Intercept. If I choose Intent Intercept it tells me that both Polaris and my app (Rollout PdfEditor) match the intent. Here is the output from Intent Interceptor:

ACTION: android.intent.action.VIEW

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

FLAGS: 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 ACTIVITIES MATCH THIS INTENT: 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! if you look at the documentation for <category /> it says:

Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. 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. 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. You can find documentation about BROWSABLE here. It reads:

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.

Try this 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.

这篇关于如何让我的应用程序出现在应用程序选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆