-1

I have some codes like this for saving image to gallery,

But it says deprecated for "getExternalStoragePublicDirectory"

I know i need to use MediaStore or getExternalFilesDir or something

But don't know how to

Thanks

private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
        currentPhotoPath = image.getAbsolutePath();
        return image;
    }
Onur Kaya
  • 1
  • 1

2 Answers2

0

try this for new Function getExternalFilesDir

File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
milan pithadia
  • 840
  • 11
  • 16
  • Thanks for your answer lot but it is not getting into Gallery it's saving into myapp.files.Pictures how can we make the saving directory gallery(public) – Onur Kaya Jan 28 '21 at 07:29
0

Just change this line of code:

File storageDir = getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

To:

File storageDir = applicationContext().getFilesDir()
Hascher
  • 486
  • 1
  • 3
  • 12