orgzly-android
orgzly-android copied to clipboard
Implement a Tasker extension for invoking synchronization
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.
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. )
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 https://github.com/orgzly/orgzly-android/issues/315#issuecomment-381704021 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 https://github.com/orgzly/orgzly-android/issues/8#issuecomment-304738355 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).
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.
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.
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.
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
.
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?
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).
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
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.
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.
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.
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.
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?
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.
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.
@codygman: I'm not sure I understand the exact issue. Is it about initiating the sync, or sync conflict after that?
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)
@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.
Since the recent update the command has changed. Intent should be sent to BroadcastReciever class: com.orgzly.android.ActionReceiver
.
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?
Do we have any working setup avaible?