Memory-Assistant icon indicating copy to clipboard operation
Memory-Assistant copied to clipboard

Environment.getExternalStorageDirectory is deprecaterd and needs to be replaced with Storage Access Framework

Open maniksejwal opened this issue 5 years ago • 2 comments

Environment.getExternalStorageDirectory has been deprecated in Android Q. It should stop working in Android R. This is done to ensure privacy.

The new alternative for File handling is the Storage Access Framework.

https://github.com/baldapps/Flipper is a library that helps in keeping the old behaviour and can be tried.

maniksejwal avatar Nov 14 '19 02:11 maniksejwal

@shetyeanuja can you mention the resolving commit in this thread

maniksejwal avatar Oct 06 '22 19:10 maniksejwal

Instead of Helper.APP_FOLDER directory for saving the file, we can use getFilesDir()

//After API 23 permission request is asked at runtime
int EXTERNAL_STORAGE_PERMISSION_CODE = 23;
//Requesting Permission to access External Storage
        ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                EXTERNAL_STORAGE_PERMISSION_CODE);
//It creates an app-specific directory, hidden from users and deleted with the app
        File folder = getActivity().getFilesDir();

shetyeanuja avatar Oct 07 '22 04:10 shetyeanuja