Writing to external SD card in Android 5.0 and above

(Pavel) #82

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.

0 Likes

(Audrius Butkevicius) #83

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.

0 Likes

(Pavel) #84

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

0 Likes

(Audrius Butkevicius) #85

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

0 Likes

(Jakob Borg) #86

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.

0 Likes

#87

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

(Luca1234567) #90

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

0 Likes

(Catfriend1) #91

The explanation is in there:

0 Likes

#92

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.

0 Likes

(Simon) #93

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.

0 Likes

(Catfriend1) #94

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.

0 Likes

(Hans Peter Jansen) #95

@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.

0 Likes

(Catfriend1) #96

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

(Hans Peter Jansen) #97

@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

(axet) #98

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.

0 Likes

(Audrius Butkevicius) #99

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

0 Likes