视频未显示在 android Gallery 中

问题描述

我在我的应用中生成一个视频,我希望它可以被照片/画廊应用发现。创建文件后,我调用 addVideoTogallery,它使用 FileProvider,然后调用 ACTION_MEDIA_SCANNER_SCAN_FILE 意图。

请在下面找到所有必需的代码段。关于为什么我的文件 deos 没有出现在照片/图库应用中的任何想法?

private Uri getimageUri(File file) {
    return FileProvider.getUriForFile(this,this.getPackageName() + ".provider",file);
}

private void addVideoTogallery(File videoFile) {
    Uri contentUri = getimageUri(videoFile);
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(contentUri);
    this.sendbroadcast(mediaScanIntent);
}

private File getVideoFile() {
    String filename = TEST_VIDEO_FILE_NAME + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ".mp4";
    if (isExternalStorageWritable()) {
        currentFile = new File(getExternalFilesDir(null),filename);
    } else {
        currentFile = new File(getFilesDir(),filename);
    }

    return currentFile;
}

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.time.example.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <Meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></Meta-data>
        </provider>

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="external"
        path="Android/data/com.time.example/files" />
</paths>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)