Skip to content Skip to sidebar Skip to footer

Mysterious NullpointerException After The Built-in Camera App Saves My Video Properly

I have an activity that allows you to record a video if you open a dialog and click on an icon. The problem is that after I stop recording it throws a NullPointerException even tho

Solution 1:

Try this:

private static File getOutputMediaFile(int type)
{
  File mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

    if (! mediaStorageDir.exists()){
        if (! mediaStorageDir.mkdirs()){
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String mediaFile;
    if (type == MEDIA_TYPE_IMAGE){
        mediaFile = "IMG_"+ timeStamp + ".jpg";
    } else if(type == MEDIA_TYPE_VIDEO) {
        mediaFile = "VID_"+ timeStamp + ".mp4";
    } else {
        return null;
    }

    return new File(mediaStorageDir, mediaFile);
}

The getExternalStorageDirectory method returns a File object, not a string you can append a subdirectory to.

It also wonder if the directory returned by that method would be available to a service. The Android specs say:

On devices with multiple users (as described by UserManager), each user has their own isolated external storage. Applications only have access to the external storage for the user they're running as.

LOL!!!! Just realized this question was asked 2 years ago! Did you find the answer yet?? LOL


Post a Comment for "Mysterious NullpointerException After The Built-in Camera App Saves My Video Properly"