2

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:

  1. Environment.getExternalStorageState(directory) = mounted
  2. ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) = 0
  3. 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.

  • Have you added run-time permissions to this application? – cjnash Jan 02 '19 at 18:43
  • I did. I'm even checking that I have permission to that directory and it claims I do. See troubleshooting #2. – Destiny Faith Jan 02 '19 at 18:47
  • Try to use this permission checker to check for run-time permissions: https://stackoverflow.com/a/34084609/8065149 – cjnash Jan 02 '19 at 18:50
  • 1
    `this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED` = true – Destiny Faith Jan 02 '19 at 18:56
  • Hmm. I would do a little more digging to make sure that what you are trying to do is possible. Reading this answer makes it seem like what you are tying to accomplish is infeasible: https://stackoverflow.com/a/51385515/8065149. However, i have only been looking around for a couple minutes and might be wrong. – cjnash Jan 02 '19 at 18:58
  • I do have root, so I can try to use `WRITE_MEDIA_STORAGE` – Destiny Faith Jan 02 '19 at 18:59
  • I tried running `pm grant package "android.permission.WRITE_MEDIA_STORAGE"` in shell but that didn't seem to fix it. – Destiny Faith Jan 02 '19 at 19:03
  • Update: It's throwing an exception `Operation not allowed: java.lang.SecurityException: Permission android.permission.WRITE_MEDIA_STORAGE is not a changeable permission type` – Destiny Faith Jan 02 '19 at 19:05
  • "I am requesting permissions, granted them, and I'm even getting a response in troubleshooting #2 that I do have permission" -- all of that is for [external storage](https://commonsware.com/blog/2017/11/14/storage-situation-external-storage.html). Your USB stick is [removable storage](https://commonsware.com/blog/2017/11/15/storage-situation-removable-storage.html). You do not have access to arbitrary locations on removable storage. – CommonsWare Jan 02 '19 at 22:12
  • How do I not have access to _arbitary locations on removable storage_ if it works perfectly fine in kitkat and the SDK 25 device is on kitkat? @CommonsWare – Destiny Faith Jan 03 '19 at 13:46
  • Your KitKat device perhaps was upgraded from some earlier version of Android. KitKat is API Level 19, not 25. – CommonsWare Jan 03 '19 at 13:48
  • I'm talking about two different devices. One device is kitkat and it works perfectly fine, one is rooted 25 and it gives me a permissions error. – Destiny Faith Jan 03 '19 at 13:51

0 Answers0