[英]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 ). 对于其他类型的文件,您可以通过MimeTypeMap( http://developer.android.com/reference/android/webkit/MimeTypeMap.html )获得其MIME类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.