嗨,我正在尝试使用文件提供程序从内部存储播放视频。我的代码如下:
val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val apkURI = FileProvider.getUriForFile(
this,
this.getApplicationContext()
.getPackageName() + ".provider",
File(item.path))
intent.setDataAndType(apkURI, "video/mp4")
startActivity(intent)
在Android清单中,我通过以下方式添加了提供程序:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="android.sample.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
提供商路径
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>