简体   繁体   中英

how do I get my file manager app to start a file when clicked Android?

I am working on a basic file manager, and I am having trouble starting a file. I have it so that when you click a folder it opens, but how do I get it to start a file when a file is clicked? Thanks!

For video or audio, you can start the file like this,

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

and for other types of files, you can get its MIME type through MimeTypeMap ( http://developer.android.com/reference/android/webkit/MimeTypeMap.html ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM