Unable to access external media

3,321 views
Skip to first unread message

Harrison Bond

unread,
Jul 3, 2021, 9:33:55 PM7/3/21
to Automate
Unlike access to the built in sd card slot on my phone, which mounts to `storage/`, the usb-c sd card reader I have appears to be accessible from a `/tree/` path like `/tree/0000-0000:`.  I can access this location from the external storage settings prompt, but I can't seem to get the `storage media mounted?` to trigger when the card reader is mounted. I'm unable to select the same `/tree` path in the mounted block, and manually entering it into the path input doesn't work either.

This used to work just the same as the internal SD card (as a `/storage` subpath), but I believe when I upgraded to Android 11 it stopped due to changes in the filesystem API.  Since upgrading, I have reinstalled the Automate app, re-enabled all permissions, and re-selected all external storage paths.  Is there something new I need to do to access usb devices with Android 11?

Henrik "The Developer" Lindqvist

unread,
Jul 3, 2021, 10:09:23 PM7/3/21
to Automate
Accessing external USB drives isn't part of standard Android, i think, but some manufacturers may support it.
Google has butchered file access more and more since Android 10, so manufacturers stop supporting it in Android 11 could be expected.

Harrison Bond

unread,
Jul 3, 2021, 10:49:20 PM7/3/21
to Automate
I can access the drive from any file manager I use, both first-party Samsung and third party like Cx File Explorer.  They all work the same as they always have.  Given that Automate can get permission from the file dialog like it does with `/storage/` mounted volumes, is there really no other way to support these other drives?  Would be a bummer if the importing app I built was permanently disabled and I had to go back to tediously doing things manually again.

Henrik "The Developer" Lindqvist

unread,
Jul 4, 2021, 2:42:49 PM7/4/21
to Automate
The third-party file manager may have implemented USB storage access separately, while the Samsung one has root privileges with access to the mount point, e.g. /mnt/media_rw/0000-0000

John Charlton

unread,
Jul 5, 2021, 2:20:57 PM7/5/21
to Automate
I have Android 11 on a Samsung S10 and explored this a bit.

1) Due to "Storage Access Framework" first I add the external drive using the picker in Automate setup.
This gives me a path of /storage/3BF7-184B

2) When I attempt to add a path into the Storage Media Mounted block, /storage returns a permission denied fault.  The app cannot list this directory, it is only allowed to access folders within it is has permission for and knows the path.
When the picker is on /storage, I can type in 3BF7-184B manually and it accepts the path.storage/3BF7-184B

The block fails to function.

3)  I also tried storage/3BF7-184B/DCIM in the storage media mounted block and thst fails also

****
4)  I now tried a "file list" block.  I entered "storage/3BF7-184B" using Fx it is accepted, and the file list block works perfectly with no issues.
I repeated with "storage/3BF7-184B/DCIM" and this also works perfectly, generating an array of file/path names.
The files/paths names are "storage/3BF7-184B/*

****

5) OK, so now I tried a "File Exists?" block using "storage/3BF7-184B/DCIM" enteted as Fx
FAIL!
This generates a fatal exception:
com.llamalab.safs.NoSuchFileException: /storage/emulated/0/3BF7-284B

Where did it get that path from?  It's not even the correct path.

-J

Henrik "The Developer" Lindqvist

unread,
Jul 5, 2021, 3:20:18 PM7/5/21
to Automate
  1. Indeed, ensure the drive is added in External storage settings.
  2. Try writing in the mounting point path manually, or paste it. This may not work with "/storage/<drive hex>" as it's not a "mounting point" path, so try with "/mnt/media_rw/<drive hex>.  I'll probably have to implement a custom (file) picker for "mounting points."
  3. Probably not work because of #2, unless there's any other error message?
  4. The File blocks are accessing through simulated/emulated paths, e.g. /storage..., not through the "mounting point" path, since those are usually inaccessible to app.
  5. Ensure the path started with / otherwise it's relative to the primary secondary storage, e.g. /storage/emulated/0/...

John Charlton

unread,
Jul 5, 2021, 3:42:53 PM7/5/21
to Automate
1) in my first post ^^ I was mistakenly accessing the built in sd-card slot.  I didn't try inserting and removing that so I don't know if the "is mounted" block works or not with that... but the f"ile exists?" block did have the mentioned fail.

2) Automate shows the EXTERNAL drive as "/tree/84B9-3B6D:"   When I try this nothing works, I get similar null response the same as when I enter random characters/non existent path.
3) A file manager that does work fine with the external drive (X-Plore) names the path of the extetnal drive as
"/mnt/media_rw/84B9-3B6D

And when I try THAT path in automate I get "Permission Denied" .... the path exists but Automate didn't properly secure permission?  The apparently correct path is not the one in Automate settings. (the /tree/* thing is not a valid system path so why does it have permission for that and not the actual path...?)

sorry about my confusion between internal sd slot and external usb drive earlier


-J

John Charlton

unread,
Jul 5, 2021, 4:15:18 PM7/5/21
to Automate

"X-Plore" file manager is a third party app, I had to grant it permission then it has full access.

Screenshot_20210705-161307_X-plore.jpg

Henrik "The Developer" Lindqvist

unread,
Jul 6, 2021, 12:22:02 AM7/6/21
to Automate
Okay i think i know what the issue is.
USB drives is indeed accessible through SAF (Storage framework), but my code seems to handle it improperly, hence the "/tree/84B9-3B6D:", which is paret of the SAF file URI, not the file path. Maybe it changed in Android 11. I'll investigate.

Harrison Bond

unread,
Jul 6, 2021, 7:31:33 PM7/6/21
to Automate
Let me know if you need me to test an update.  Thank you for the quick response and investigation!

Harrison Bond

unread,
Oct 2, 2021, 4:55:28 PM10/2/21
to Automate
Any progress on accessing external storage media?

Henrik "The Developer" Lindqvist

unread,
Oct 3, 2021, 2:37:38 AM10/3/21
to Automate
Not on this particular issue, but i'm working on the Android 11 and its forced SAF requirements now, due by November.
A problem with your issue it that i don't have any way of testing it, since i don't have an Android 11 device nor a USB drive to connect to it, but i'll try to figure out what's failing anyway.
You could help be a bit by making a simple test flow...
  1. Flow beginning
  2. App decision; Action= "android.intent.action.OPEN_DOCUMENT_TREE", Result URI: uri
  3. Log append; Message= uri
And post what is logged, i.e. the Result URI of the App decision block when choosing an external storage drive path.
Reply all
Reply to author
Forward
0 new messages