Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 保存的视频不会显示在system gallery应用程序中_Android_Video_Gallery_Google Photos_Android Mediascanner - Fatal编程技术网

Android 保存的视频不会显示在system gallery应用程序中

Android 保存的视频不会显示在system gallery应用程序中,android,video,gallery,google-photos,android-mediascanner,Android,Video,Gallery,Google Photos,Android Mediascanner,创建视频并保存后,我尝试使用以下代码扫描视频路径,使其在gallery应用程序中可见: 已保存视频的路径: public String getPath() { String videoFileName = System.currentTimeMillis() + ".mp4"; File storageDir = new File( Environment.getExternalStoragePublicDirectory(Env

创建视频并保存后,我尝试使用以下代码扫描视频路径,使其在gallery应用程序中可见:

已保存视频的路径:

 public String getPath() {
        String videoFileName = System.currentTimeMillis() + ".mp4";
        File storageDir = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                        + "/MyFolderApp");
        boolean success = true;
        if (!storageDir.exists()) {
            success = storageDir.mkdirs();
        }
        if (success) {
            File videoFile = new File(storageDir, videoFileName);
            savedVideoPath = videoFile.getAbsolutePath();
        }
        return savedVideoPath;
    }
扫描路径:

  private void galleryScanner(String path) {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        File f = new File(path);
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        sendBroadcast(mediaScanIntent);
    }
保存视频后,我像这样调用scan方法:
galleryAddPic(getPath())


怪异行为:如果我打开谷歌照片应用程序,进入相册>MyFolderApp,我可以在那里看到保存的视频,当我退出谷歌照片应用程序并返回Gallery系统时,保存的视频正常显示

String videoFileName=System.currentTimeMillis()+“.mp4”-这看起来特别可疑。您是否已验证此文件是否存在?@PPartisan感谢您的评论,是的,在访问Google Photos后,我可以在您的代码中看到以videoFileName作为itI名称的已保存视频-调用
exists()
打开
新文件(storageDir,videoFileName)
并注销结果。我怀疑您的视频使用了错误的文件名。执行此操作后:
if(videoFile.exists())Log.d(“file”,“I'M exists”);else Log.d(“文件”,“我不存在”)我知道我不在日志中,所以你没有正确的文件名。而不是使用
String videoFileName=System.currentTimeMillis()+“.mp4”
,在创建文件的任何位置获取文件名,并将其传递给方法。
String videoFileName=System.currentTimeMillis()+“.mp4”-这看起来特别可疑。您是否已验证此文件是否存在?@PPartisan感谢您的评论,是的,在访问Google Photos后,我可以在您的代码中看到以videoFileName作为itI名称的已保存视频-调用
exists()
打开
新文件(storageDir,videoFileName)
并注销结果。我怀疑您的视频使用了错误的文件名。执行此操作后:
if(videoFile.exists())Log.d(“file”,“I'M exists”);else Log.d(“文件”,“我不存在”)我知道我不在日志中,所以你没有正确的文件名。而不是使用
String videoFileName=System.currentTimeMillis()+“.mp4”
,在创建文件的任何位置获取文件名,并将其传递给方法。