Application selection dialog based on filetype

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 16:05:10

问题


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?

回答1:


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


来源:https://stackoverflow.com/questions/7635764/application-selection-dialog-based-on-filetype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!