根据文件类型的应用程序选择对话框 [英] Application selection dialog based on filetype

查看:174
本文介绍了根据文件类型的应用程序选择对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个对话框,将显示菱应用程序的列表,打开特定文件类型。

I'm trying to create a Dialog, which will display a list of availible applications to open a given filetype.

我一直期待在这里计算器具有相同问题工作的一些问题,但我迷路由于缺少答案。特别是我一直在寻找这样一个问题:

I've been looking at some question here on stackoverflow that work with the same issue, but I get lost due to lacking answer. In particular I've been looking at this question:

<一个href=\"http://stackoverflow.com/questions/4834374/in-android-how-can-i-display-an-application-selector-based-on-file-type\">In Android的,我怎么能显示基于文件类型的应用程序选择?

我的跟进问题是,那么:

My follow-up question is then:


  • 做什么用的列表与LT; ResolveInfo&GT;

  • 如何显示与名称和图标的应用菱?

  • 当用户选择一个应用程序,我怎么能启动它根据所选项目的ResolveInfo?

推荐答案

我发现了一个解决方案,即给我的,可以打开一个给定的MIME类型的应用程序的完整列表。这是不是最好的,因为我想名单更具体,只是几个应用程序(例如,如果这是我想打开浏览器仅会显示了一个URL),但供应的目的。

I found a solution, that gives me a full list of applications that can open a given mimetype. It's not the best, as I would like the list to be more specific and just a few applications (e.g. if it was an URL I wanted to open only browsers would show up) but serves the purpose.

下面是我做过什么:

File file = new File( "myFileLocation.txt" );
String extension = MimeTypeMap.getFileExtensionFromUrl( file.getPath() );
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);

Intent intent = new Intent();
intent.setAction( Intent.ACTION_VIEW );
intent.setDataAndType( Uri.fromFile( file ), type );    
context.startActivity( intent );

这篇关于根据文件类型的应用程序选择对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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