Writing to external SD card in Android 5.0 and above

Is it able to access external card via Android NDK ?

It should be a simple task to implement go wrapper over C++ (NDK) code. I think porting syncthing to android was much more harder to do.

The issue talks about accessing internal storage which we don’t have problems accessing. It states that you only needs permissions to access external storage, which was perhaps true in 2012, but is no longer true.

Will not insist, as I’m not Android programmer, seems this restriction is done in Dalik/ARM virtual machine, not by Linux kernel/SELinux. At least, I can do “shell@E5333:/storage/sdcard1 $ echo > a” from shell. I belive, utilities like “echo” and even Dalvi/ARM are build with Adnoid NDK, and they have write ablity to external sd. It’s just an opinion, sorry if I’m wrong.

Thanks, it works! And I also found out the updates on the manifest file will only take effect after you re-install the app. 2015-06-16

Well, compile a Go binary and see if you can get a go binary to do that without root.

As with all things Android I expect there is variation between ROMs. Maybe yours doesn’t enforce this. I’m pretty sure other variants do, or this issue would have been a non issue. There’s also no indication the comment you quote relates to 5.0+. The rest of the post predates 5.0 by years.

Hi all, I read through the entire thing and wanted to add that I was also able to get it to sync to my SD card without rooting my device or adding the card as internal or adopted. Below will be to add my experience after following the steps of the post from AnnoyingDuck in December 2017. Also ran using the WebGui where possible as advised by Cooad in April 2017 on this thread.

My Phone: Moto G5S plus Running Android 7.1.1 Not Rooted SD card is formatted as external, haven’t done anything besides put it in my phone.

Followed Steps 1, 2 and 3 from AnnoyingDuck’s post with no problem. I opted to not have my phone and computer sync just yet though, and instead wanted to test making a folder on my external SD card via SyncThing. As Annoyingduck said you do want to use the Advanced Folder Picker option.

When I went add the folder Syncthing gave me the warning: Android version does not allow syncing to external SD card etc. but somehow after plugging that path in a couple times, it was suddenly an option in the list of possible paths when I backed out and tried to create a folder again.

I chose the SD card option, named the folder Music (which matched the Music folder I had set up to sync on my computer). Went back to my computer, told it to share the folder with my phone, received the request. I guess since the names of the files were both music it just recognized that was where it was supposed to go so it started syncing the computer to the folder I’d created.

In case you aren’t extremely technical and have no idea where to get your SD file path from, an app I had used in the past called OneSync (used to sync OneDrive) showed it. So I redownloaded that and wrote down my file path.

Sorry if that’s a lot, I’m not very technically savy, I just hoped this would help others like me who don’t know much beyond how to follow instructions found on the internet to a certain degree.

2 Likes

On my device Sony Xperia Z3 compact with Android 6.0.1 I test Syncthing Android v1.1.0 from Google Play Store.

If I use a path like /storage/0000-0000/Test/Syncthing, when I try to change “Folder Type” I receive this message “Your Android versiononly grants Syncthing readonly access to the selected folder”. But I see that Syncthing create the “.stfolder”, so it can write to the SD card to crate “.stfolder”.

I set up the the folder to sync to PC. I set up by web interface the folder as “Send&Receive”. When it try to sync reply, all file are in status “… acces denied”, and it can’t sync file.

I thing you may investigate on why “.stfolder” can create, but the other file and folder not.

Bye

The explanation is in there:

This is the only thing that keeps me from using Syncthing everywhere. It is USELESS on an Android phone. It is also NOT an Android problem as I have many apps on my Android 8 un-rooted phone that can write to ANY folder on my SD card. It is due to the fact that Syncthing is written in GO and GO cannot request correct permissions on Android. There are no DEVs that want to write an Android client in another language (Java?) that can request permissions correctly. None of this is meant to talk down about anyone. I just wish it wouldn’t be stated that this is because of “Android restrictions” It is because of Android permissions that Syncthing cannot access.

To me the second sentence immediately invalidates the first: Android imposes restrictive permissions, which prevent not only Go/Syncthing, but any program from directly accessing the files, instead needed to access that through an Android API. This is a restriction by Android - whether you consider it a good one or not is another question and quite irrelevant.

This is misunderstood “top1”. I’ve switched all our phones at home to official unrooted Android meanwhilst and the ones having an sdcard can write to it using Syncthing. You just have to use the special folder the app suggests to you when creating a new one on Android and your write access is there.

@Catfriend1 Well, I’m inclined to note, that you talk about sightly different things. You will spot the difference, if you try to sync the DCIM folder (or some arbitrary other folder outside of “Android/data/com.nutomic.syncthingandroid”) on your SD card.

Being on Xiaomi mi8, I can sync /storage/emulated/0/DCIM with readwrite. I even have full access to /storage/emulated/0 and sync that in both directions. On sdcard, /DCIM is read only, so that’s where I think your statement fully applies.

1 Like

@Catfriend1 Exactly. And given that older phones at least are space constraint, hence relocating DCIM to the SD card is a very common operation. Syncing this folder would give a beautiful workflow: delete unwanted pics and relocate valuable pics to different folders on the PC, and a sync would clean up DCIM automatically. IF only Google wouldn’t be such a PITA.

Google don’t care about DCIM on SD cards, because their phones don’t have a SD card slot. For (about) the same reasons, they prioritize GO language extensions, that don’t buy them much…

Of course, advanced users could use this pattern much more widespread: I used to sync ebooks, mp3, business docs, source code, but the whole SAF disaster spoils the fun, and syncthing (usage) is the victim.

Given, that typical folders in emulated (builtin) storage don’t need the SAF, the whole security blather is pretextual for their own advantage.

In fact, using syncthing on portable devices has some other trade offs (energy-wise), but this very issue is enough to not even care/report about the other issues, because it broadly limits syncthing’s usefulness on such devises.

I’m back to oldschool cut’n’paste on a case by case base, because of this at least (while I’m using syncthing successfully in many other use cases, btw).

2 Likes

To make external sd card access, syncthing-android should move from syncthing binary to syncthing library with extended api to call file IO’s. gomobile build should be a build utility. I’ve done for android torrent using torrent go library.

Sure, that’s what should happen, sadly nobody has enough time, ambition or knowledge to do this.

This is quite a shame, it’s the one thing holding me back from being able to completely switch from Resilio Sync. Dammit google.

As I understand it, the two primary proposed solutions to this point are:

  1. Implement syncthing natively in Java/Kotlin and use SAF to prompt the user for access to the SD root, and to access files and directories.

  2. Create a thin layer in Java/Kotlin which uses SAF, and use some sort of socket or pipe protocol to interface with that layer from Go.

Unfortunately, from watching this video (relevant part linked, but the whole thing is very informative): https://youtu.be/UnJ3amzJM94?t=1193

It appears to me that neither approach will yield a solution, because GOOG explicitly does not want people using SAF for broad file access. I think the only solution is getting approval for “All files access”, which according to the video doesn’t sound very easy. I do think there’s a good chance syncthing could qualify though.

What’s worse, I’m pretty sure these issues aren’t just going to affect SD cards. If I understand correctly, these enforcements are coming to internal/external storage as well. Am I missing anything?

I used sync thing at Android 9 (MIUI Version) and was surprised hat the SD-Card problem was gone. Why worked it at android 9?

Thought hat this problem was solved with android 9, but since the todays upgrade to android 10, I can not sync to the android device again. :unamused:

In MIUI is no option to format the sd as internal storage ?

There is no other way to fix it currently?

No, there is no workaround.