Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a Tasker extension for invoking synchronization #231

Open
novoid opened this issue Nov 24, 2017 · 22 comments
Open

Implement a Tasker extension for invoking synchronization #231

novoid opened this issue Nov 24, 2017 · 22 comments

Comments

@novoid
Copy link

novoid commented Nov 24, 2017

Hi,

The well known Android tool Tasker offers the possibility to invoke external hooks of Android apps that provide such a "plugin" mechanism. (I am sure there is a specific term for this I don't know yet.)

It would solve many people's problems when Orglzy would come with such an Tasker plugin extension so that my Tasker is able to do a sync whenever it suits my requirements.

Background info:

In my case, the beta auto-sync function does not work for me because I do have huge Org-mode files. When I activate "sync whenever Orgzly is started", I have to wait a couple of minutes(!) before I could actually use Orglzy because during the sync, Orglzy behaves not normal. I can't search, I can't navigate.

Therefore, I'd prefer a sync in the morning, when I leave the house (loosing my WiFi network). I am sure that other people do have other preferences such as entering the company's WiFi, or every other hour or or or. Instead of implementing complex "when to sync" functionality into Orgzly, users could benefit from the awesome possibilities of Tasker.

@nevenz
Copy link
Member

nevenz commented Nov 24, 2017

Plugin would be cool, in the meantime, you can do this by sending an intent - see this comment.

I've tried it now by creating a new action System -> Send Intent:

Action
com.orgzly.intent.action.SYNC_START

Package
com.orgzly

Class
com.orgzly.android.sync.SyncService

Target
Service

( Enabling "Sync status" notification in Orgzly is useful in this case BTW. )

@novoid
Copy link
Author

novoid commented Jun 9, 2018

While the workaround using the intent worked for a couple of months, I now got:

code 3: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.orgzly.intent.action.SYNC_START cmp=com.orgzly/.android.sync.SyncService }: app is in background uid null. which results in not synchronizing.

Current setup:

  • Tasker v5.1m
  • Orgzly 1.6.6
  • Android 8.1.0

I found a helpful explanation for the changed behavior with #315 (comment) which requires to switch from "startservice" to "start-foreground-service" starting with Android Oreo. Issue #315 further mentions solutions/workarounds for the app "Automate" but not for Tasker.

However, https://github.com/claiire updated #8 (comment) where the process for Tasker was explained in the first place:

  • Open up tasker and go to the Profiles tab.
  • Click the + at the bottom-center of the screen and select Time
  • Leave From alone. Uncheck To, check Repeat and put in the update interval you'd like.
  • Now that you've set up your Context for updating, go back to the Profile screen and there should be an Enter task box hovering over your new profile. Hit New Task, give it a name like "Sync Orgzly" or something, and hit the checkmark. This should open the Task Edit screen.
  • Add a new Action to the Task with the plus button at the bottom of the screen. Select Code > Run Shell on the popup.
  • In the Command field, write am startservice --user 0 -a com.orgzly.intent.action.SYNC_START com.orgzly/com.orgzly.android.sync.SyncService
    Tasker should now sync orgzly every x minutes/hours/whatever you used. Probably. I'm bad at this stuff and new to it.

This works for me (again).

@nevenz
Copy link
Member

nevenz commented Jun 9, 2018

I found a helpful explanation for the changed behavior with #315 (comment) which requires to switch from "startservice" to "start-foreground-service" starting with Android Oreo.

Currently, sending a broadcast instead is recommended:

  • Action: com.orgzly.intent.action.SYNC_START
  • Class: com.orgzly.android.ActionReceiver

Support for sending SYNC_START to SyncService might be removed in the future.

@novoid
Copy link
Author

novoid commented Jun 9, 2018

Hi @nevenz,

What do I have to enter as command? Because am startservice --user 0 -a com.orgzly.intent.action.SYNC_START com.orgzly/com.orgzly.android.ActionReceiver did result in an error 255 with no sync process initiated.

@nevenz
Copy link
Member

nevenz commented Jun 9, 2018

What do I have to enter as command?

adb shell am broadcast -a com.orgzly.intent.action.SYNC_START com.orgzly/.android.ActionReceiver

I should probably document this somewhere.

@novoid
Copy link
Author

novoid commented Jun 9, 2018

Still an error. Are you sure about the com.orgzly/.android.ActionReceiver part?

Also an error when using am broadcast -a com.orgzly.intent.action.SYNC_START com.orgzly/com.orgzly.android.ActionReceiver. Also for am broadcast -a com.orgzly.intent.action.SYNC_START com.orgzly.android.ActionReceiver.

@nevenz
Copy link
Member

nevenz commented Jun 10, 2018

Still an error. Are you sure about the com.orgzly/.android.ActionReceiver part?

Yeah, first two work for me. What's the error, the same?

@novoid
Copy link
Author

novoid commented Jun 10, 2018

Well, I don't get it.

Yesterday and up to now, all I got with am broadcast -a com.orgzly.intent.action.SYNC_START com.orgzly/com.orgzly.android.ActionReceiver with interactively starting the task was:

15.17.41/E Run Shell:  ->
15.17.41/E Run Shell:  ->
15.17.41/E Run Shell:  ->
15.17.41/Shell runBackground am broadcast -a com.orgzly.intent.action.SYNC_START com.orgzly/com.orgzly.android.ActionReceiver root: false timeout: 1000
15.17.41/Shell start process-thread ID 283
15.17.41/E add wait type Shell1 time 2147483647
15.17.41/E add wait type Shell1 done
15.17.41/E add wait task
15.17.41/E Error: 255

The task is associated with booting my phone (in the morning).

Now, after an additional reboot, it worked: Orgzly synchronized the local files.

However, when I manually start the task in Tasker, the error 255 persists.

As long as it works when I boot my mobile, I'm fine with it. Let's see and watch how this turns out within the next days.

Still: it's be awesome when Orgzly provides a Tasker add-in so that I can invoke sync as a 3rd party action or as an action plugin (don't know what the difference is).

@DerBeutlin
Copy link

What seems to work for me is:

Tasker -> Send Intent

Action: com.orgzly.intent.action.SYNC_START
Package: com.orgzly
Class: com.orgzly.android.ActionReceiver

This is probably what @nevenz mentioned before

@novoid
Copy link
Author

novoid commented Jun 12, 2018

Thanks @Nelsonlittle for clarification - I did not get that before.

I just checked again:

  • Tasker -> Send Intent
  • Action: com.orgzly.intent.action.SYNC_START
  • Package: com.orgzly
  • Class: com.orgzly.android.ActionReceiver

... does not work at my side.

  • Tasker > Run Shell
  • Command: am startservice --user 0 -a com.orgzly.intent.action.SYNC_START com.orgzly/com.orgzly.android.sync.SyncServic

... currently works on my side.

@nevenz
Copy link
Member

nevenz commented Jun 17, 2018

I just checked again:

Tasker -> Send Intent
Action: com.orgzly.intent.action.SYNC_START
Package: com.orgzly
Class: com.orgzly.android.ActionReceiver

... does not work at my side.

What Target did you use? It needs to be Broadcast Receiver.

@novoid
Copy link
Author

novoid commented Jun 17, 2018

Oh, thanks for clarification. I used the default one which was not Broadcast Receiver.

However, changing it to Broadcast Receiver did not result in Orgzly syncing.

@nevenz
Copy link
Member

nevenz commented Jun 17, 2018

However, changing it to Broadcast Receiver did not result in Orgzly syncing.

Hmm, I'm not sure what could be the issue. It's hard to debug without seeing logs. If you have adb you might be able to see what's happening. Although there might not be enough useful infromation without debugging enabled in the app. I do see at least:

06-17 21:36:26.153  1648  1665 I ActivityManager: Start proc 22497:com.orgzly/u0a104 for broadcast com.orgzly/.android.ActionReceiver

when I run Tasker's task.

@rieje
Copy link

rieje commented Jun 19, 2019

I could not find intent or plugin in documentation--if intents work, shouldn't they be documented? Otherwise, it seems like intents may no longer be supported.

Only just started using Tasker and Orgzly was my immediate thought to take advantage of this. Surprised this isn't a higher priority and curious what the plans are for automated syncing. At the moment I'm using the experimental auto-sync feature but it isn't capable of auto-syncing in the background.

Sorry for noob question, but when should SYNC_STOP be used? I was under the impression that SYNC_START will initiate a sync and once it's done it's done. Is SYNC_STOP ever necessary?

@nevenz
Copy link
Member

nevenz commented Jun 21, 2019

I agree sync intents should be documented. If someone wants to take a shot, /help page is at https://github.com/orgzly/documentation/blob/master/miscellaneous.org.

Is SYNC_STOP ever necessary?

It's not, it's there for completeness.

@codygman
Copy link

I'm trying to send a sync event to orgzly when a folder is modified but having trouble. I started trying to send a sync event and "sync..." popup with a delay for just a file and that doesn't seem to work either.

I do have a this UX for when I switch to orgzly though and it limits the amount of conflicts I get drastically. The only difference from the orgzly "sync on resume/leave app" is that there is a popup that stays on screen for 1 second.

@nevenz
Copy link
Member

nevenz commented Dec 24, 2020

@codygman: I'm not sure I understand the exact issue. Is it about initiating the sync, or sync conflict after that?

@ugurbolat
Copy link

These are the parameters to send syncservice command:
Package: com.orgzly
Service Class: com.orgzly.sync.SyncService
Action: com.orgzly.intent.action.SYNC_START
"Start ub foreground state" enabled (without this,I got "app is in background uid null" error)

@novoid
Copy link
Author

novoid commented May 6, 2022

@codygman: I'm not sure I understand the exact issue. Is it about initiating the sync, or sync conflict after that?

It's about initiating the sync.

@sh-zam
Copy link

sh-zam commented Oct 12, 2022

Since the recent update the command has changed. Intent should be sent to BroadcastReciever class: com.orgzly.android.ActionReceiver.

@nulinspiratie
Copy link

nulinspiratie commented Jan 22, 2023

Since the update I haven't been able to get Tasker to sync properly. I've been using the parameters of @ugurbolat and the updated intent of @sh-zam .

Has anyone recently managed to get Tasker to send a sync command? If so could you write down the parameters used?

@falematte
Copy link

Do we have any working setup avaible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants