Stack Overflow archive
0 score

Open files from own file explorer

score
0
question views
57
license
CC BY-SA 3.0

Something like this should work. Change file to whatever you want.

java
File file = new File(Environment.getExternalStorageDirectory(), "movie.mp4");
int index = file.getName().lastIndexOf(".") + 1;
String extension = null;
if (index > 0) {
    extension = file.getName().substring(index);
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri u = Uri.parse("file://" + file.getAbsolutePath());
String mimeType = null;
if (extension != null) {
    mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
if (mimeType == null) {
    mimeType = "*/*";
}
intent.setDataAndType(u,  mimeType);
try {
    startActivity(Intent.createChooser(intent, "Open with..."));
} catch (ActivityNotFoundException e) {
    // handle the exception
}

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.