android android.provider.MediaStore.ACTION_VIDEO_CAPTURE return null onActivityResult with nexus 7

后端 未结 3 857
春和景丽
春和景丽 2020-12-31 16:20

I am using intent for record video.

so i use following code on recordVideo button\'s click

Videofilepath = \"\";
Intent intent = new Intent(android.p         


        
3条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 16:59

    Thanks for the workaround!

    Here is more brushed and copy-paste usable code:

    /**
     * Create intent to take video.
     */
    public static Intent createTakeVideoIntent() {
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        Uri uri = getOutputVideoUri();  // create a file to save the video in specific folder
        if (uri != null) {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        }
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
    
        return intent;
    }
    
    
    @CheckForNull
    private static Uri getOutputVideoUri() {
        if (Environment.getExternalStorageState() == null) {
            return null;
        }
    
        File mediaStorage = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "YOUR_APP_VIDEO");
        if (!mediaStorage.exists() &&
                !mediaStorage.mkdirs()) {
            Log.e(YourApplication.TAG, "failed to create directory: " + mediaStorage);
            return null;
        }
    
        // Create a media file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
        File mediaFile = new File(mediaStorage, "VID_" + timeStamp + ".mp4");
        return Uri.fromFile(mediaFile);
    }
    

    Tested on Nexus 4 v4.3 JWR66Y

提交回复
热议问题