Writing to external SD card in Android 5.0 and above

Since currently there is no way to provide external storage to the native binary, it won’t work unless Syncthing binary adds an API for providing external data, or most of Syncthing’s functionality is re-developed in Java. I don’t think this going to happen soon, so the more realistic scenario is that sooner or later Android Document Provider API is somehow supported in Go.

I don’t know how you could use Java for that. Youd’d have to call Java from Go, and I don’t think that is possible. Afaik the solution is using the NDK from Go.

Edit: Wtf everyone commented at the same time :smiley:

I did this on a Sony Xperia Z2 running Android 6.01, that is not rooted, to sync the pictures on the sdcard. I copied the file .stfolder from /storage/cardid/Android/data/com.nutomic.syncthingandroid/files/ to /storage/cardid/DCIM/Camera. Added a new folder to sync and selected the /storage/cardid/DCIM/Camera folder and it’s syncing right now to the server.

I recently got a Huawei P9 running 6.0, and syncing to and from SDcard works fine. I do not think it’s using Merged Storage, since the system settings show the SD card still as “portable storage”.

Sadly I do not remember exactly the process, but I remember authorizing something when I was using ES File Manager and attempted to copy something manually onto my SD card from the internal storage. It had me select my SD card through some system dialogue, and syncthing has worked since then without problem. Wish I had more info on why it worked, or if it would work with anyone else’s situation, but just glad it worked :slight_smile:

1 Like

Hello, I am currently on the Android version 0.8.4 (0.14.6) hornor 7 and android 6 I save all my sdcard I synchronize my nas with v0.14.9 version of Linux (ARM) everything works very well when I delete from my nas is also delete on my Android when I add photos to my nas that is added on my android (I do not understand the comment that you can not write on a sdcard aves synthing) Except for the Version 0.8.6 or 0.8.7 is the case, why chagnement what? Thank you in advance for your answers

bonjour, je suis actuellement sur la version android 0.8.4 (0.14.6) hornor 7 android 6 je sauvegarde tout sur ma sdcard que je synchronise sur mon nas avec la version v0.14.9, Linux (ARM) tout marche tres bien, quand je suprime depuis mon nas c’est aussi suprimé sur mon android quand je rajoute des photos sur mon nas c’est ajouté sur mon android (je ne comprend pas les commentaire comme quoi on ne peut pas ecrire sur une sdcard aves synthing) Sauf que depuis la version 0.8.6 ou 0.8.7 c’est le cas , pourquoi ce chagnement que faire ? merci d’avance pour vos reponses

The only change in 0.8.6 is the folder picker, which doesn’t show folders on external storage devices any more. You can still select external devices if you enable the advanced folder picker in the app settings.

Thank you for the quick reply. I think it has to come from the android version that forcing others change. I’ll stay in Version 0.8.4

merci pour la réponse rapide. je pense que ca doit venir de la version android qui a forcement d’autres changement. je vais rester sous la version 0.8.4

To allow UTG usb drive to be formatted as internal storage call this:

# adb shell sm set-force-adoptable true
1 Like

Is this something that is planned to be supported, as it seems a major flaw to be able to sync all our data?

It is not planned. My personal opinion is that any effort towards it is probably better spent improving a native Android solution like https://github.com/davide-imbriaco/a-sync-browser.

2 Likes

I have a Motorola MotoG3 running Android 6.0.1. I was not quite aware, that this should not be possible, so i’ve set up a folder to sync on my phone. I did it from the web interface (I’ve changed the bind address in the app, and logged in from my pc) - I set up the folder first on my PC, then shared it to the phone and confirmed through the web gui of the phone syncthing instance, giving the path to the folder (/storage/“card”/Music). Aaand… It works, flawlessly. It detects changes on the card, it can write new files, modify them - all is well. So why is it said, that it doesn’t work?

Did you format the card as portable storage, or as internal storage? Internal will always work, but portable only on some devices with non-standard implementations by the vendor.

Also, some ROMs are known to fix the android limitation

It’s set up as portable storage. So it works only because of Motorola’s changes to the system? Well good for me, I guess :slight_smile:

Well, it’s sad, that this golang issue still isn’t fixed.

Moving the .stfolder from /storage//Android/data/com.nutomic.syncthingandroid/files/ to SdCard root did the trick for me on Xiaomi device based on 6.0.1. I was able to sync the whole SdCard.

This, right here.

I’m going to chime in here. I’m able to fully sync (read & write) folders on my external SD card in Android 7.0 without root and WITHOUT formatting my SD card as adoptable storage (I kept it in it’s removable exfat format). Tested on my Moto X Pure running stock Android 7.0 and on my LG-G3 running Lineage 14.1 Android 7.1.2. In the Android app under Settings/Behavior there is an option to use the Advanced Folder Picker, check this off. My external sd card is labeled /storage/0123-4567 on my device. This number will vary depending on your phone. In this particular setup I’ll explain how I sync my entire 90gb music library to my external 128gb sd card on Stock Android 7.0, MotoXPure:

1: Add your computer to Android by scanning it’s ID. Wait for it to add, and don’t select any folders to share with it.

2: On your Android, create the folder you want to sync with and create a .stfolder inside the folder (or just add a .stfolder to an existing folder if you already have the folder created the device).

3: On the computer create a new folder share within Syncthing’s GUI. In my case it was my Music folder on my PC. Select the device to share the folder with (your Android) and choose all of your preferences. I turn all file versioning off for my needs and on my PC I was sure to set it as “Send Only” so that I can’t screw up and delete something from my PC’s master music folder.

4: Wait for the notification to appear on your Android, then click it when it arrives. Name the sync to whatever you want and then in the “Path” area select your external sd (which will be labeled something like /storage/0000-0000). Then once the SD is selected, navigate to the folder on the external sd that you’ll be syncing (in my case it’s /storage/0123-4567/Music).

5: Now wait for the devices to re-communicate with each other and syncing will begin. You may need to restart Syncthing on both devices to get it to initiate.

6: That’s it…both folders are now syncing. Any music file I add from my PC will write to my phone’s external SD if Syncthing is running. Even though I am rooted, root is not required.

Note: Both of my folders (music on PC and music on Android’s external sd) were both already on each device. After setting up the sync, the initial scan took quite a while to complete (about 40min), but after that it’s working properly. All changes are synced immediately based on your selected scan interval. I took one album and changed the tags & embedded a cover image into each mp3 file and they were synced to my Android almost immediately. Can’t be happier, this is working great.

1 Like

That is not supposed to work. Maybe LineageOS has a change that allows this, or you installed some app or script that allows it.

1 Like

The only downside is that the computer shows that it’s still syncing (hangs at 95%) and the phone says it’s out of sync. But it’s not, all files/changes are synced correctly. I don’t know, seems to just work.

A new (I think) proposal for using the Android SAF from go without having to do any cross-language calls. This is going to be a little odd, but as far as I can tell it will work. The ingredients in this insane plan are:

  1. UNIX domain sockets, to which both Android Java and Go have access (I think), and, in particular, the ability to pass file descriptors across UNIX domain sockets.

  2. Some code in the syncthing-android service which knows how to drive the SAF in response to commands received across a socket connection.

  3. Some code in syncthing itself to provide a synthetic mountpoint; a filesystem driver in parallel to basicfs which knows how to translate requests for files below the mountpoint into commands on the socket.

Does this seem like a reasonable plan? I’d be happy to start prototyping if so.