Android 11 storage issues

Viewed 52

I have to migrate the app from android 10 (API level 29) to android 11 (API level 30) according to new Google policy. And now I have an issue with lunching the camera for taking a picture.

Here is my code:

    private File imageFile;
    private void createImageFile() throws IOException {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";

    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );
    imageFile = image;
  }

When I'm creating the temporary file it throws an exception (only in Google and Motorola phones) or . What I need to do to make it work?

0 Answers
Related