The following code which consists of downloading a file from a server and save it in the storage works fine when the device has an internal storage.
But when I tried it
This attribute is "false" by default on apps targeting Android 10 or higher.
<application android:requestLegacyExternalStorage="true" ... >
...
</application>
It is possible that the device requires that you manually give the permissions to the cell phone, check your equipment and check that the write permission is activated on your device.
Try using mkdirs instead of mkdir. If you are creating a directory path and parent doesn't exist then you should use mkdirs.
I had the same problem, and i solved it by disabling file transfer from device to computer. Because if u enable file transfer, sd card is not accessible to debugging application.
i have done very silly mistake. I have already put in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
and also add permission in java file,as get permission pragmatically. But there is mistake of Manifest.permission.READ_EXTERNAL_STORAGE. Please use Manifest.permission.WRITE_EXTERNAL_STORAGE.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);