0

ダウンロード マネージャーを使用して、ファイルを外部ストレージにダウンロードしました。を使用してダウンロード先をダウンロードフォルダーに設定しました

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)

成功したら、URIを取得します

val fileUri=cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))

これは私にこれを与えます

file:///storage/emulated/0/Download/dishapatani_Jan%2007%2C%2008%3A07_1609986166669.mp4

今、私はこれでインテントを使用してこのビデオファイルを再生しようとしています

  val uri=Uri.parse(" file:///storage/emulated/0/Download/dishapatani_Jan%2007%2C%2008%3A07_1609986166669.mp4")
        val intent = Intent()
        intent.action = Intent.ACTION_VIEW
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)

        val contentUri = FileProvider.getUriForFile(requireContext(), requireContext().packageName + ".provider", File(localUri))

        intent.setDataAndType(contentUri, "video/mp4")
        intent.setData(contentUri)
        startActivity(intent)

ここで内容ウリはcontent://com.myapp.provider/external_path/dishapatani_Jan%252007%252C%252008%253A07_1609986166669.mp4

しかし、action_shareインテントを使用すると、再生も認識もされません。

また、file:// を含むファイル uri を削除して、/storage/emulated/0/Download/dishapatani_Jan%2007%2C%2008%3A07_1609986166669.mp4 に置き換える必要があります。そうしないと、root が構成されていないと言ってアプリがクラッシュします。

これが私のプロバイダーパスです

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_path" path="/Download" />
</paths>

そしてマニフェスト

 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
4

1 に答える 1