Reputation: 16570
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:
List<ResolveInfo>
?Upvotes: 3
Views: 919
Reputation: 16570
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 );
Upvotes: 3