sdcard-path-discovery.md
2.06 KB
SDCard Path Discovery on Android
Problem
On Android 10+ and certain OEM skins, /sdcard/ is a symlink or FUSE mount that may not be directly accessible from all contexts (especially under su or from Termux). The actual external storage path is often /storage/emulated/0/.
Discovery Workflow
When file operations on /sdcard/ fail with "Permission denied" or "No such file or directory", run:
# Check where /sdcard actually points
su -c "readlink /sdcard" # May show /storage/self/primary
su -c "ls -la /sdcard" # May be empty or permission denied
# Check the real FUSE mount point
su -c "cat /proc/mounts | grep fuse"
# Typical output:
# /dev/fuse /storage/emulated/0 fuse ...
# /dev/fuse /mnt/user/0/emulated fuse ...
# Check EXTERNAL_STORAGE env var
su -c "echo $EXTERNAL_STORAGE" # Usually /sdcard
# Verify the actual path works
su -c "ls -la /storage/emulated/0/"
Resolution
Always use /storage/emulated/0/ as the canonical path for VisualAgent directories:
# Correct
COMMANDS_DIR="/storage/emulated/0/VisualAgent/commands"
RESULTS_DIR="/storage/emulated/0/VisualAgent/results"
# May fail depending on context
COMMANDS_DIR="/sdcard/VisualAgent/commands"
In Practice
This session encountered the issue where:
mkdir -p /sdcard/VisualAgent/commandsfailed with "Permission denied"su -c "mkdir -p /sdcard/VisualAgent/commands"succeeded but created at/storage/emulated/0/VisualAgent/commands- The command files were actually at
/storage/emulated/0/VisualAgent/commands/ read_fileandwrite_filetools failed on/storage/emulated/0/VisualAgent/paths with "Permission denied"- Only
terminalwithsu -cworked for file operations
Key Takeaway
For Android automation backends, always:
- Use
/storage/emulated/0/as the canonical external storage path - Use
su -cfor all file operations on external storage - Use
terminaltool (notread_file/write_file) when running in Termux/cron context - Test path accessibility with
su -c "ls -la /storage/emulated/0/"before assuming it works