I have an android device running SDK 25 (rooted). I'm inserting a USB stick into it and trying to create a file on that USB stick /storage/2EC8CD9EC8CD64A5/test.txt
but it keeps throwing an IOException saying I don't have permission.
I am requesting permissions, granted them, and I'm even getting a response in troubleshooting #2 that I do have permission.
I've done the following troubleshooting:
Environment.getExternalStorageState(directory)
=mounted
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
=0
- My manifest has
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
and in the above I do have permission for it.
EDIT: I have attempted to use ContextCompat.getExternalFilesDirs(context, null)[1]
, however, those files do get remove from the removable device when the application is installed when these files need to stay on the device.
This app isn't for consumers or normal phones, only devices my company manages.
I've tried looking into android.permission.WRITE_MEDIA_STORAGE
but can't find a way to grant that permission via shell.