根据文件类型的应用程序选择对话框

问题描述:

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

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:

In Android的,我怎么能显示基于文件类型的应用程序选择?

我的跟进问题是,那么:

My follow-up question is then:


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

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

  • 当用户选择一个应用程序,我怎么能启动它根据所选项目的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 );