1

When I write the following line of code it seems to have no problems, but I understand that getExternalStoragePublicDirectory is deprecated since Android 10:

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/" + getString(R.string.app_name));

But when I write the code like this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/" + getString(R.string.app_name));
    }

Android Studio underlines the word getExternalStoragePublicDirectory indicating that it is deprecated

Why doesn't it tell me without having to check the Android version? I need to know when the code is deprecated without having to wrap the code in an "if"

This is what I have in gradle

compileSdk 31

defaultConfig {
    vectorDrawables.useSupportLibrary = true
    applicationId "com.list.ssss"
    minSdk 19
    targetSdk 31
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

I also tried following these steps to see if it told me that getExternalStoragePublicDirectory is deprecated but it didn't work either

JP711
  • 533
  • 6
  • 15

0 Answers0