Android的启动应用程序选择器与应用相应列表 [英] Android Launching an application chooser with appropriate list of applications

查看:299
本文介绍了Android的启动应用程序选择器与应用相应列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我已经看到几个线程和教程这个话题,我想我还是有一个关于如何应用程序可以选择从应用程序的列表,以显示文件中的一些困惑。

Although I have seen several threads and tutorials on this topic, I guess I still have some confusion on how an application can be chosen from a list of applications to display a file.

我有一个活动已在它的列表视图。这个列表视图绑定文件路径(所以各种各样的文件浏览器)。当我们点击一​​个特定的文件类型,我需要的应用程序可以打开的文件列表。

I have a Activity which has a list view in it. This list view is bound with file paths (so a file browser of sorts). When we click on a specific file type, I need a list of applications that can open that file.

到目前为止,这是我在OnItemClick列表项:

So far this is what I have in the OnItemClick for the list item:

Intent myIntent = new Intent();
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.addCategory("android.intent.category.DEFAULT");
myIntent.setData(Uri.fromFile(new File(filePath)));

当我运行这个在我的手机,错误的是: 无活动处理意向{行为= android.intent.action.VIEW猫= [android.intent.category.DEFAULT] DAT =文件:///

When I run this on my phone, the error is: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] dat=file:///

当我在文件浏览器应用程序(从市场上下载)一样,我得到两个选项(的Quickoffice和Word走),这两个我已经安装在我的手机上。

When I do the same in a file browser application (downloaded from the marketplace), I get two options (QuickOffice and Word to Go), both of which I have installed on my phone.

有人能指导我一下,还有什么需要在这里?除了上面我已经试过的东西:

Could someone guide me as to what else is needed here? Things I have tried besides the above:

  1. 添加以下条目清单:

  1. Add the following entries to the manifest:

<意向滤光器>      <作用机器人:名称=android.intent.action.MAIN/>      <类机器人:名称=android.intent.category.LAUNCHER/> &所述; /意图滤光器> <意向滤光器>   <作用机器人:名称=android.intent.action.VIEW/>   <类机器人:名称=android.intent.category.BROWSABLE>   <类机器人:名称=android.intent.category.DEFAULT>   <数据机器人:计划=文件/> < /意图滤光器>

<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" /> <category android:name="android.intent.category.BROWSABLE" > <category android:name="android.intent.category.DEFAULT" > <data android:scheme="file" /> </intent-filter>

明确设置类型:

myIntent.setDataAndType(Uri.fromFile(新File(文件路径)),*);

无论这个工作,任何帮助是AP preciated。

Neither of this works, any help is appreciated.

谢谢!

推荐答案

首先, 不是一个MIME类型*。你必须使用 setDataAndType()并提供真正的MIME类型。如果你不知道真正的MIME类型,你不能建立自己的应用程序。

First, * is not a MIME type. You have to use setDataAndType() and supply the real MIME type. If you do not know the real MIME type, you cannot build your application.

二,我会摆脱 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) addCategory(android.intent.category.DEFAULT),除非你有你需要的确凿证据。

Second, I would get rid of the addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) and addCategory("android.intent.category.DEFAULT") unless you have absolute proof that you need them.

三,关于您的活动的意图过滤器什么都没有做任何其他活动的意图过滤器,所以你尝试过在#1的过滤器将没有关系,而且也应该删除。

Third, the intent filters on your activity have nothing to do with the intent filters of any other activity, and so all those filters you tried in #1 will not matter and probably should be removed.

这篇关于Android的启动应用程序选择器与应用相应列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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