This code allows you to open a particular file with the default application, specifying the MIME, in these cases audio and video.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.mp4");
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.mp3");
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
10 Comments
Other formats how to do? For example: .txt, .doc, .zip
Open Any type of file with Default Intent
@zx012345, for text formats you use "text/*", others as .doc and .zip depends on which is the default application
http://helloworldcodes.blogspot.com/2011/10/android-open-folder-with-default.html
here you can find the way to open a file even if you don't know the mime type of any file. i have successful experience with second method listed there.
First time be here, nice website.
That website not related to Android intents, unless you're trying to buy purses using intents :D
Thanks a lot, that was very helpful
I am so glad that I have bookmarked this website because I see that it is full of various and attractive information about Html Coding. Thanks one more time for this publication, it was really interesting to update. Web Design Dubai
This code is not working for .torrent files. Kindly tell me what will be the code. I want to select between installed torrent supported fapps (utorrent.bittorrent)
This code is not working for .torrent files. Kindly tell me what will be the code. I want to select between installed torrent supported fapps (utorrent.bittorrent)