Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a file can be opened by a third party application before download

Tags:

android

In my application I want to download a file and view it. The issue is that I need to check whether there is any third party application installed on the device that can open the file format(Mime) before it is downloaded. Is this possible?

like image 580
sha Avatar asked Mar 19 '12 13:03

sha


1 Answers

Create an ACTION_VIEW Intent with the right MIME type and a fake path to the file (or, better yet, the path you intend to download it to). Then, use PackageManager and queryIntentActivities() -- if you get back a list with 1+ items in it, then startActivity() on that Intent will succeed once you have downloaded the file.

like image 67
CommonsWare Avatar answered Sep 29 '22 06:09

CommonsWare