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);
3 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.