开发者

Application selection dialog based on filetype

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, How can I display an application selector based on file type?

My follow-up question is then:

  • What to do with the List<ResolveInfo>?
  • How can I display the availible applications with name and icon?
  • When the user selects an application, how can I start开发者_运维问答 it based on the ResolveInfo of the selected item?


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.

Here is what I did:

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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜