如何从文件管理器打开应用程序并直接播放视频? [英] how to open app from file manager and play video directly?
问题描述
我正在尝试制作视频播放器应用.我可以通过手动打开我的应用程序来播放视频.但我想将我的应用程序显示为如下图所示的选项:
I am trying to make a video player app. I can play video by opening my app manually. But I want to show my app as an option like below picture:
简而言之,当我单击文件管理器中的任何视频文件时,这会将我的应用程序显示为播放该视频的选项.当用户点击我的应用程序时,这将打开一个特定的活动并开始播放该文件.我该怎么做?
in short, when I click any video file in file manager, this will show my app as an option for playing that video. When user click on my app this will open a particular activity and start playing that file. How can I do this?
推荐答案
将下面的代码添加到inside activity(that you want to open) inside manifest:
Add the below code to inside activity(that you want to open) inside manifest:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="video/*"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
</intent-filter>
在您的活动中使用以下代码以获取文件的 uri.我已经在 exoplayer
中测试了路径.
use below code to your activity to get the uri of your file. I have tested the path in exoplayer
.
Uri uri = getIntent().getData();
这篇关于如何从文件管理器打开应用程序并直接播放视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!