I try to create a small file explorer on Android, and I want the system to open files when an existing application, as the default file explorer does.
For instance, if you click on a MP3 file, I want to open the media player, and the pdf reader for the PDFs, and so on.
I wasn’t able to find any source on Internet. I’m currently using this:
try {
Intent myIntent = new Intent(
android.content.Intent.ACTION_VIEW, Uri
.parse("file://"
+ myFile.getAbsolutePath()));
startActivity(myIntent);
} catch (Exception e) {
Log.e(TAG, "Not possible to resolve this intent.");
Toast.makeText(getApplicationContext(),
"This file cannot be opened from here.",
Toast.LENGTH_SHORT).show();
}
But it only works for a PDFs… Any ideas about how I can have the same behavior than the file explorer without setting the right MIME type ‘manually’ in the intent?
Here is the code source of the whole project: https://github.com/rbochet/Rhizome-Retriever
Android does not have a “file explorer”, let alone a “default” one.
You can’t. Add the MIME type.