1

I am trying to create a directory in my Seconday External Storage(SD Card) but mkdir() returns false. I have provided as the necessary permissions,the App is targeting API 29.

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

   <application>
     ...
       android:requestLegacyExternalStorage="true"
    </application>



 if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            } else {
                ActivityCompat.requestPermissions(this,
                    arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.READ_EXTERNAL_STORAGE),
                    MY_PERMISSIONS_REQUEST_STORAGE);
            }
        }

These are the Permissions that I have provided.When I am working with Primary Internal Memory the Directory is getting created. The path of the folder where I want to /storage/3C03-69OD/Folder

3C03-69OD - External SD Card.

 var externalFiles=ContextCompat.getExternalFilesDirs(this,null)
    val myDirectory = File(externalFiles[1].parentFile!!.parentFile!!.parentFile!!.parentFile!!.absoluteFile, "/Folder")
Log.i("Path",myDirectory.absolutePath) //[Produces /storage/9C33-6BBD/Folder]
    
     if (!myDirectory.exists()) {
              Log.i("Create", myDirectory.mkdir().toString())
       }

0 Answers0