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);
5 Comments
Other formats how to do? For example: .txt, .doc, .zip
@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.
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