简体   繁体   English

单击Android时,如何使我的文件管理器应用程序启动文件?

[英]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.

相关问题 当从任何应用程序(如文件管理器)打开 PDF 文件时,我希望我的应用程序出现在选择器对话框中。我该怎么做? - I want my app to appear on the chooser dialog when opening PDF file from any app like file manager ..How I do this? 单击我的Widget时如何启动活动? - How do I start an Activity when my Widget is clicked? 如何添加到我在Android应用程序上创建的文件? - How do I add to the file i created on my android app? 如何在Android应用中加载OpenCV Manager软件包? - How do I load the OpenCV Manager package in my Android app? 如何在 Android Studio 的文件管理器中获取我保存的照片 - How to get my saved photos in this file manager in Android Studio 如何在 android 应用程序中提示文件管理器进入已知路径? - How I can prompt a file manager into a known path in an android app? 当从外部应用程序(如whatsapp或facebook)单击链接时,如何启动我的Android应用程序? - How to start my Android application when a link clicked from external app like whatsapp or facebook? 如何开始打包我的Android应用程序? [KIVY] - How do I start packaging my app for android? [KIVY] 如何在Android应用程序的“开始”屏幕上添加徽标? - How do I add logo on my start screen in android app? 应用启动android时如何从内部存储读取文件 - How to read file from internal storage when app start android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM