How to create the sync folder without UI (FolderActivity) correctly


(Boris Brakhin) #1

Hi to everyone ! Please help !!!

I can’t create a sync folder in my MainActivity for example by clicking on some button on it.

In my OnClick event for button my code is :

Folder mFolder = new Folder();
mFolder.id = generateRandomFolderId();
mFolder.path = Local_folder_path;
mFolder.label = Remote_deviceID;
mFolder.fsWatcherEnabled = true;
mFolder.fsWatcherDelayS = 10;
mFolder.rescanIntervalS = 3600;
mFolder.paused = false;
mFolder.type = Constants.FOLDER_TYPE_SEND_RECEIVE;
mFolder.versioning = new Folder.Versioning();
mFolder.addDevice(Remote_deviceID);
mFolder.order = "oldestFirst";
getApi().createFolder(mFolder);

After the clicking on button new folder appears in the Sync Folders List, it attached to the remote device but all files in it DON’T SYNC with remote device.

And it doesn’t sync when i use another code :

Intent intent = new Intent(MainActivity.this, FolderActivity.class);
intent.putExtra(FolderActivity2.EXTRA_NOTIFICATION_ID, 0);
intent.putExtra(FolderActivity2.EXTRA_IS_CREATE, true);
intent.putExtra(FolderActivity2.EXTRA_PATH, Local_folder_path);
intent.putExtra(FolderActivity2.EXTRA_DEVICE_ID, Remote_deviceID);
intent.putExtra(FolderActivity2.EXTRA_FOLDER_LABEL, Remote_deviceID);
MainActivity.this.startActivity(intent);

What are the solvings of this problem ?


(Jakob Borg) #2

I think this is a development question? Reclassifying. And you can use triple backticks around code for better formatting.

```
code here
```

(Boris Brakhin) #4

So, can anybody help me ?


(Audrius Butkevicius) #5

What does the folder look like in the web UI? I man it’s your code, it’s likely you’ll have to debug it yourself.


(Catfriend1) #6

Maybe you just miss a restart or repost of the config to syncthing rest api ? Is this near the official master code and what would you like to achieve? Try restApi.saveConfigAndRestart


(Boris Brakhin) #7

Before setting out my goal, I would like to draw attention to how synchronization works in Syncthing Android example:

  1. On the local device (LD) in DeviceActivity, the remote device ID (RD)
  2. The event onDeviceRejected is processed by the EventProcessor on RD - Notification is generated and the DeviceActivity is started via PendingIntent, then the Device is created equivalent to LD
  3. The FolderActivity is started on the RD and the Folder associated with the LD is created.
  4. The event onFolderRejected is processed on the LD through EventProcessor - Notification is generated and through FolderActivity the FolderActivity is started via PendingIntent, then the Folder associated with the RD is created

After that, the folders created on LD and RD are perfectly synchronized.

Now about my purpose and the essence of my question. I do not need to create a Folder through FolderActivity, because the Folder properties are not entered from the UI, but are formed from the code and are known in advance. Therefore, the order of actions is as follows:

  1. On the local device (LD) in DeviceActivity, the remote device ID (RD)
  2. The event onDeviceRejected is processed by the EventProcessor on RD - Notification is generated and the DeviceActivity is started via PendingIntent, then the Device is created equivalent to LD
  3. On the RD from the code
Folder mFolder = new Folder ();
mFolder.id = generateRandomFolderId ();
mFolder.path = --- Local Folder Path ---;
mFolder.label = deviceID;
mFolder.fsWatcherEnabled = true;
mFolder.fsWatcherDelayS = 10;
mFolder.rescanIntervalS = 3600;
mFolder.paused = false;
mFolder.type = Constants.FOLDER_TYPE_SEND_RECEIVE;
mFolder.versioning = new Folder.Versioning ();
mFolder.addDevice (--- deviceID of LD--);
mFolder.order = "oldestFirst";
getApi (). createFolder (mFolder);

creates a Folder associated with LD

  1. If the event onFolderRejected is processed on LD, Notification is generated and FolderActivity is started via PendingIntent, then the Folder associated with the RD is created - FOLDERS SYNCHRONIZATION WORKS If, on the onDeviceRejected EventProcessor handler, you create a Folder from the code described above - FOLDERS DO NOT SYNCHRONIZE.

How can I implement the creation of a Folder from the code so that they are successfully synchronized?


(Boris Brakhin) #8

The question is removed - I figured out, everything works :slight_smile:


(system) #9

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.