MediaStore.ACTION_VIDEO_CAPTURE 未在牛轧糖 7.0 中保存视频 [英] MediaStore.ACTION_VIDEO_CAPTURE not saving the video in Nougat 7.0

查看:35
本文介绍了MediaStore.ACTION_VIDEO_CAPTURE 未在牛轧糖 7.0 中保存视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Intent 从 Nougat 7.0 录制和保存视频,我可以录制视频,但它没有保存在设备存储中.我什至使用 FileProvider 来避免FileUriExposedException".但是当涉及到捕获图像时,它会保存在下面指定的路径中.这是我的代码.

Hi i have been trying to record and save a video from Nougat 7.0 using intent, I can record a video but its not getting saved in the device storage. I even used FileProvider to avoid 'FileUriExposedException'. But when it comes for Capturing Images it is getting saved in the below specified path. Here is my code.

    private Uri imageUri;
    private File imageFile = null;
    public File videoFilePath() {
            return new File(getDefaultCameraPath(), "Video_" + System.currentTimeMillis() + ".mp4");
        }
private void callCameraIntent(){
    Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    imageFile = videoFilePath(); 
    imageUri = FileProvider.getUriForFile(CreatePostActivity.this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(cameraIntent, 2);
}
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
           if (resultCode != Activity.RESULT_CANCELED) {
            //Here it returns imageFile does not exist so it skips the if statement
            if (resultCode == Activity.RESULT_OK && requestCode == 2 && imageFile != null && imageFile.exists()) {

                }
        }
    }

以上代码适用于所有 pre-Nougat 版本.谁能为我提供更好的解决方案来录制视频并保存在设备存储中.

The above code works well for all the pre-Nougat version. Can anyone provide me a better solution to record the video and save in device storage.

推荐答案

这里是解决方案!

如果您的 targetSdkVersion 是 24 或更高,我们必须使用 FileProvider 类来授予对特定文件或文件夹的访问权限,以便其他应用程序可以访问它们.

If your targetSdkVersion is 24 or higher, we have to use FileProvider class to give access to the particular file or folder to make them accessible for other apps.

Stackoverflow 链接:android.os.FileUriExposedException: file:///storage/emulated/0/test.txt 通过 Intent.getData() 暴露在应用程序之外

Stackoverflow link: android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

您还应该检查所需的权限 android.Manifest.permission.CAMERA

also you should check the required permission android.Manifest.permission.CAMERA

这篇关于MediaStore.ACTION_VIDEO_CAPTURE 未在牛轧糖 7.0 中保存视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆