SDCard Write Access

711 views
Skip to first unread message

James Cross

unread,
Jul 23, 2015, 5:28:02 AM7/23/15
to Automate
Found automate to be really useful, copying things to my home NAS when on power and WiFi.  I found the pen on my note 4 to be very useful to work with the flows.

What I'm struggling with is write access to the SD card. My note 4 has lollipop and so in theory I can make a folder accessible to an application.  I want to copy files from my NAS to the SD card but cannot get write access and phone memory is limited.  I can read  it just fine and other apps on my phone can write to it ok.

What am I missing?

I'm a bit unsure as to which path to use as there seem to be a few that point to the same folder on the fs.

Automate developer

unread,
Jul 23, 2015, 2:24:19 PM7/23/15
to Automate, ja...@jcross.co.uk, ja...@jcross.co.uk
Since Android 4.4 Google prevents apps from writing to secondary external storage, i.e removable SD cards:
https://groups.google.com/forum/#!topic/android-platform/14VUiIgwUjY[1-25]
http://www.androidcentral.com/kitkat-sdcard-changes

This means the File blocks wont work on a removable SD card. It still may still work on some device where the manufacturer has grant the required permission even to apps, since they don't want their customer complaints for what Google has done.
Non of my devices have a removable SD card, so i was unaware of this issue until recently, from another issue report.

Sadly i haven't found a workaround yet, so the only option may be to add new blocks for working with the Documents API.

James Cross

unread,
Jul 24, 2015, 3:15:05 AM7/24/15
to Automate
It looked like you may be able to access a folder if it had the right name. Com.automate.something

Also I noted on my phone that there are a few paths that lead to the same location. So this may be a manufacturer fudge to make that work. I don't understand the android paths.

Automate developer

unread,
Jul 24, 2015, 2:34:52 PM7/24/15
to Automate, ja...@jcross.co.uk, ja...@jcross.co.uk
Yes, Automate can probably access its own directory "/data/com.llamalab.automate/" on the removable SD card, but only that.

Paths leading to the same location are called symlinks:
https://en.wikipedia.org/wiki/Symbolic_link

yohannes....@gmail.com

unread,
Jul 27, 2015, 8:07:16 AM7/27/15
to Automate, ja...@jcross.co.uk, henrik.l...@gmail.com
I've tried this. Created the folder /data/com.llamalab.automate/ under "Android" folder in the removable SD card. Added the folder path to put WhatsApp Images.
Then I used the file monitor block to monitor WhatsApp Images on its own folder. I use (1) file created (2) writable file closed (3) read-only file closed events to trigger the next block. The next (and final block) only moves the captured file from WhatsApp's folder into the one in the removable SD card.
I ran the flow. Saved an image from within WhatsApp.
The file didn't get moved to the intended folder.
Is there anything wrong with my programming? Or is it simply that Automate can't move the file, even to this specific folder?
Please help. Thank you.

yohannes....@gmail.com

unread,
Jul 27, 2015, 8:50:33 AM7/27/15
to Automate, ja...@jcross.co.uk, henrik.l...@gmail.com, yohannes....@gmail.com
Update: I changed the path on file move block to include "/*" at the end. And for the condition on file monitor block, I just use "read-only file closed" event for the condition. Now the file(s) got moved, but the Photo Gallery app can't detect their existence anymore. (you can find/see them using File Manager)

James Cross

unread,
Jul 27, 2015, 9:47:33 AM7/27/15
to Automate
You have to deregister and re register the file in the media stor age database.

PC

unread,
Jul 27, 2015, 2:45:49 PM7/27/15
to Automate, ja...@jcross.co.uk
James, is there a shell command to do that?

Automate developer

unread,
Jul 27, 2015, 3:25:25 PM7/27/15
to Automate, my.onlin...@gmail.com, ja...@jcross.co.uk, my.onlin...@gmail.com

yohannes....@gmail.com

unread,
Jul 28, 2015, 10:36:13 AM7/28/15
to Automate, my.onlin...@gmail.com, ja...@jcross.co.uk, henrik.l...@gmail.com
I put the broadcast send block after the file move block. I set the Action and Data URI as described on the link you provided. I don't know what to fill in Package and Receiver Class fields so I left them blank.
Finally I put Add To Media Store block at the end (before looping back to File Monitor block) and used the same path defined in Destination Path field in File Move block.
The result: the files got moved as expected (no more issues on this one) but the default Photo Gallery app still doesn't detect them and the source folder still displays the broken thumbnails.
Can you help on how exactly I can de-register and re-register the files?
Thanks

Automate developer

unread,
Jul 28, 2015, 2:47:53 PM7/28/15
to Automate, yohannes....@gmail.com, my.onlin...@gmail.com, ja...@jcross.co.uk, yohannes....@gmail.com
The MediaStore is a mess, since it doesn't track file or folder deletes, it doesn't actually store "folder" either.
There's little documentation on how to remove files:
http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_SCANNER_SCAN_FILE

I don't understand now Google expects the developers to use it.
Should every file access insert, update or delete entries in MediaStore database directly!?
Removing entries are especially strange since it would have to be done before deleting the actual files, since afterward it's impossible to know which entries (in the MediaStore) to delete.
I'll probably have to implement a Media store remove block, which has to be called before deleting the files.

Try using Broadcast send block:
Action: "android.intent.action.MEDIA_SCANNER_SCAN_FILE"
Data URI: file://<path to deleted file or parent folder of deleted file/folder>

James Cross

unread,
Aug 10, 2015, 6:26:17 AM8/10/15
to Automate, yohannes....@gmail.com, my.onlin...@gmail.com, ja...@jcross.co.uk
Did we get any further with SD card access?  You can give an app and thus Automate access to a folder on the SDCard from 5 onwards, but it would have to be granted in the app somewhere I think.  Maybe a call to the system to do it once and then it will work from then on?

Automate developer

unread,
Aug 10, 2015, 9:34:56 AM8/10/15
to Automate, yohannes....@gmail.com, my.onlin...@gmail.com, ja...@jcross.co.uk
With a rooted device you can restore the old (pre 4.4) secondary external storage (SD card) access quite easily, as some manufacturer does by default.

However i've not found any easy way to make Automate access external SD card without implementing custom Document list/copy/move/delete etc.
It's not simply adding an extra permission, access has to be done using the "documents" API.

Lior Hadas

unread,
Nov 4, 2015, 5:07:52 AM11/4/15
to Automate, ja...@jcross.co.uk
i spent a lot of time debug this situation .
why does the flow continue wihtout stopping the flow , and write something relevant in the log ? 
or prevent using parameter : "extsdcard"

Automate developer

unread,
Nov 4, 2015, 2:04:21 PM11/4/15
to Automate, ja...@jcross.co.uk
Writing to a removable SD card will cause an:
java.io.IOException: open failed: EACCES (Permission denied)

I'am working on the workaround for this issue now, but a lot of work remain.

filda...@gmail.com

unread,
Aug 26, 2017, 11:32:57 AM8/26/17
to Automate
Hello guys, Is this issue already solved? Or still no way how to directly by Automate move files from internal to external SD card? If file manager programs has permission, may I give same permission to Automate? Thank for advice if exists.
Android 4.4.4, Lenovo P70 camera can not save pics to external SD and it makes me realy angry.

Henrik "The Developer" Lindqvist

unread,
Aug 26, 2017, 2:35:58 PM8/26/17
to Automate, filda...@gmail.com
Yes, grant access in Automate settings, External storage access. But not for Android 4.4.

Fra Lu

unread,
Sep 18, 2017, 4:12:25 PM9/18/17
to Automate
Any news on this? I'm struggling to do a simple flow for my mother to do this because she's having problem with the sd card itself, this could solve the problem until there's a decent card on sale... Damn google why you have to do this all so complicated T^T

Henrik "The Developer" Lindqvist

unread,
Sep 18, 2017, 6:30:40 PM9/18/17
to Automate
Reply all
Reply to author
Forward
0 new messages