I\'m working on an Android application which should be able to open a selected file from a specific folder.
I already tried this, but after selecting which applicati
MimeTypeMap.getSingleton().getExtensionFromMimeType(file.getName());
Probably, this is the easiest solution.
https://developer.android.com/reference/android/webkit/MimeTypeMap
https://developer.android.com/reference/java/net/URLConnection.html#guessContentTypeFromName(java.lang.String)
private void openFile(File file) {
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, MimeTypeMap.getSingleton().getExtensionFromMimeType(file.getName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "Open " + file.getName() + " with ..."));
}