I have an app in which user can upload file with any exetention(.png,.mp3,.txt,.pdf,.bmp,.apk,...etc)
In a nutshell-->** the file with any exe..!**
These files r displayed in list-view.
When user 'Tap' or 'click' on item from list-view intent will be called (android.content.Intent.ACTION_VIEW
) and it should be open the respective application which installed in device.
For Example
If User Click on nature.png then intent will be called and suggest the applications like Gallery,PS Touch..etc(As shown in screen shot1)
If User Click on book.pdf then intent will be called and suggest the applications like MuPdf,Polaris Office,apv..etc(As shown in screen shot2)
For .txt,.pdf,.png,.jpg-- I have solved the problem by set mime type intent.setDataAndType(Uri.fromFile(file), mime);
and also for URL
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(https://www.google.co.in/));
It is working perfectly but for rest of the file extension i m still confused- What to do? and how to do?
I have already dig around,but couldn't get satisfactorily answer..!
My Questions:
File Viewer is a FREE Android app that allows you to open and view files on your Android device. It supports over 150 file types and can display the contents of any file. You can use File Viewer's information panel to view hidden file details and metadata. Get File Viewer FREE from the Google Play store!
Press this file long and press the three vertical dots at the top. Tap “Rename,” and in the popup, you'll see the file name, the dot, and the extension. Remove the existing extension and then enter the desired extension. Press the “OK” button and tap “Rename.”
The following code will work for every file type:
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), fileMimeType);
startActivity(intent);
} catch (ActivityNotFoundException e) {
// no Activity to handle this kind of files
}
Of course, there should be an Activity
in the system that knows how to handle the file of a certain type. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With