0

The method getExternalStoragePublicDirectory() is deprecated in Android Q. Now how to save and read a file? A file may be a txt file, pdf, mht format file etc, but it would not be an image.

As there is also a way to save a file using Storage Access Framework, but it is not fulfilling my requirement as it allow user to save file where they want to save it, but I want to save a file in a specific directory as we were doing through getExternalStoragePublicDirectory() and then also display all the saved files within a list.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 2
    Does this answer your question? [Environment.getExternalStorageDirectory() deprecated in API level 29 java](https://stackoverflow.com/questions/57116335/environment-getexternalstoragedirectory-deprecated-in-api-level-29-java) – jeprubio Jun 22 '20 at 05:50
  • Please check this https://stackoverflow.com/questions/62501388/cannot-find-the-files-in-phone-storage-of-real-device-in-android-10/62501695#62501695 – Shalu T D Jun 22 '20 at 06:12

3 Answers3

1

In Android 10, You can use Scope Storage for store/read file. For Scope Storage, No Need to ask any permission also.

If you want to store your files externally means then you can use Media Store Api to access like activity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) Ref

0

You can use MediaStore API for Saving files in android Q.

val values = ContentValues().apply{ put(MediaStore.Images.Media.RELATIVE_PATH,"MyPics")

In this RELATIVE_PATH is used for the custom path.

Android 10 Storage system

0

use this code to get/create a directory, maybe it helps you

 val dirc = File(
                    context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
                        .toString() + "/your_folder/"
                )

                if (!dirc.exists()) {
                    dirc.mkdir()
                }
Mona Baharlou
  • 1,401
  • 1
  • 13
  • 26