I've a OnePlus One with rooted Cyanogen OS 12 and Tasker v4.8. I've a bash script in PC which when exiting requires a Tasker's task to be executed. I've seen the question Running a tasker task via SSHDroid (or adb shell) and although the accepted answer didn't work on my Android, the solution is very simple. To call a task, do:
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "TASK_NAME"
However, that's all I can successfully do. During exit, my script needs to pass the exit status to task so that I can continue my processing on device based on script's result.
The official guide for invoking tasks is meant for programmers, so that didn't help me. Per the thread Launch Task via Intent I attempted various ways to pass a variable's value, but to no avail.
When we invoke a task from an another task, we're given the flexibility to pass values using two variables. Those two variables can be received by the invoked task using the name %par1
and %par2
. In my demo task, all I'm doing is Alert → Flash → Text → Show me: %arg1 %par1
.
# For demonstration only, I created a task named "lol"
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "par1" --es "varValues" "received"
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "%par1" --es "varValues" "received"
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "Par1" --es "varValues" "received" # I also changed the variable name par1 to Par1 in task
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" "%Par1" --es "varValues" "received"
All those said commands execute with this output
Broadcasting: Intent { act=net.dinglisch.android.tasker.ACTION_TASK (has extras) }
Broadcast completed: result=0
Even sending this broadcast works
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -d "task:lol" --es "arg1" "received" # I setup a profile to listen to this intent and receive extra from it in a task linked to profile
But calling the task directly and then sending the variable value doesn't do anything.
So, where is the fault in my approach and/or how do I send to and receive in a variable value in a task only using command-line?
Note that I'm not looking for a workaround. I'm perfectly able to come up with many workarounds to receive exit status from my script on device, but using intent appears to be the most straightforward solution of them and I want to learn this technique too.
Update
I raised my query at:
I received this reply from Pent, both through email and on forum
You would have to be able to add a StringArrayList extra to the adb call with -e, don't know if adb can do that.
If so, to see the format you can look TaskerIntent.java http://tasker.dinglisch.net/code/TaskerIntent.java, the function addLocalVariable, if you understand java.
And that is exactly what I later surmised after posting this question.
Per the answer here, I believe a string array can be passed using adb. So I attempted some queries but again met a dead end.
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" '{"arg1"}' --es "varValues" '{"time"}'
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" '{"par1"}' --es "varValues" '{"time"}'
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es "task_name" "lol" --es "varNames" '{"par1"\,"arg1"}' --es "varValues" '{"received"\,"again"}'
I also converted the intent to URI using am to-intent-uri
and tried sending the intent URI directly, with no success again.
New update
Based on the readings viz. 1, 2 and 3, I'm absolutely sure that a string array can be passed through adb shell am
using --esa
argument. Example:
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --esa "par" "lol, cat" # value lol goes in par1 variable and value cat goes in par2 variable
That said, this query still fails:
adb shell su -c am broadcast -a net.dinglisch.android.tasker.ACTION_TASK --es task_name "lol" --esa varNames "arg1, par1" --esa varValues "lol, cat"
New update #2
You can use stock Android 6.0.1 as a testing ground.
No comments:
Post a Comment