Hi,
I have a problem with an application which should be always running in background on my android device, and sometimes, this app is shutting down.
I would like to have a tasker-task which check if this application is running, and if not, the task should relaunch the application. I have tested some stuff, but nothing is working. For example, I tried this solution : https://www.reddit.com/r/tasker/comments/6y0oee/profile_while_app_is_running_in_the_background/ New profile > Application > choose Spotify > tick "Services" (bottom left).
But it is working only when the application is in foreground.
I found some people which use the tasker notification title trigger, because this application have a notification, but I can't find the way to set this trigger correctly, the profils never become active...
Could you give me some help to do that ?
Thanks!
Tasker can not do this directly. On a rooted device, I use a script in Termux that runs pgrep against the app in question,then calls that script via a run shell action in Tasker.
The "pgrep -x <package name>" command will not work without root permissions even if run from the command line in a terminal app.
This runs in a loop on my device checking periodically if the app is still in the background. If I were to use this perpetually, then I think I would use a time profile to check every XX minutes, which would be more battery friendly.
I use the run shell action because it's a quick way to get the PID of the app's process back to tasker without needing another profile for an intent received. The %pgrep variable contains the PID of the running app or the %pgrep is unset if the app is not running.
Termux script:
Code:
#!/system/bin/sh
su -c pgrep -x com.sirius
exit 0
Tasker run shell action:
Code:
Run Shell [
Command:sh /data/data/com.termux/files/home/.termux/tasker/pgrep
Timeout (Seconds):0
Use Root: On
Store Output In:%pgrep
Store Errors In:%pgrepErr
Store Result In:
Continue Task After Error: On
]
Actually, there a slightly easier way. It dawned on me the other day that I had never tried the command "pidof", and it turned out it's available on android.
Still requires root though.
Code:
A1: Run Shell [
Command: pidof net.dinglisch.android.taskerm
Timeout (Seconds): 0
Use Root: On
Store Output In: %pidof
Store Errors In: %pidofErr
Store Result In:
Continue Task After Error: On
]
A2: Wait [
MS: 300
Seconds: 0
Minutes: 0
Hours: 0
Days: 0
]
A3: Flash [
Text: PID: %pidof
ERR: %pidofErr
Long: On
]
Related
This is /sort/ of a development question; if the mods feel it's more properly in Q&A, please move it.
First off, a little disclosure; "IANAP".
Okay, here goes:
Currently I am trying to create what ought to be a /very/ simple script using "am" (as in; am start -a blahblah -n blahblah/.blah ) in order to invoke an activity for a specific application. Unfortunately, apparently the activity can only be called viably from //within// the application.
The app in question is "redditisfun" ( http://github.com/talklittle/reddit-is-fun ). The activity in question is ".InboxActivity". So far, I can get the first bit of code to pull up the app, but the second bit fails out due to lack of permission.
1)
Code:
am start -a android.intent.activity.MAIN -n com.andrewshu.android.redditdonation/.RedditIsFun
2)
Code:
am start -a android.intent.activity.MAIN -n com.andrewshu.android.redditdonation/.InboxActivity
I've tried it with "broadcast" rather than "start" -- that throws no errors, but simply does nothing. (logcat shows no activity that I can see.)
So here's my question; how does one send a system call to an app that is already running, using am? I am afraid that none of the documentation I've yet found says anything at all about this.
So I'm attempting to duplicate the task on my incredible where I can mimic a power button push/hold as a task or by covering the proximity sensor to first give the power menu then to turn the screen off if still . covered. Using tasker and execute locale plugin i run the command
@1sendevent /dev/input/event4 1 116 1
sleep 1
!sendevent /dev/input/event4 1 116 0
However the event number and code are not the same. There is a process to discover them using adb which I have never been able to set up.
the process listed in post 34 here http://groups.google.com/group/tasker/browse_thread/thread/2c98667f14f69a3f/a385a2c4497a8ddd by hypnotoad details the instructions. Is there a way to do this using an app like terminal? adb has never worked with me for the tp and os x. If someone knows the answer or could help out that would be awesome. My terminal and programming skills are not of expert qualities. thanks a bunch.
solved my own dilemma
So I was able to figure this out by inadvertently having to root my replacement Incredible on OS X Lion (As a side note, this was quite the process taking over 4 hours for me because Unrevoked refused to work and I have ADB issues, there was quite a bit of trial and error. I still do not have nand unlock, but I was able to restore my backup, so I digress).
First if you're running Easy Tether and have issues, try running this in terminal
sudo /System/Library/Extensions/EasyTetherUSBEthernet.kext
For whatever reason, that never fixed my ADB issues before, but, it worked this time. To reload when done with ADB
sudo kextload /System/Library/Extensions/EasyTetherUSBEthernert.kext
Now either using Tasker or Locale and the Execute plugin the command needed is
@!sendevent /dev/input/event1 1 107 1
sleep 1
!sendevent /dev/input/event1 1 107 0
the '@' simply keeps the toast from appearing, leaving it a much cleaner process, the '!' is required as a root access.
Drop it as an icon as a task shortcut and voila, instant power button savior. Unfortunately the touchpad doesn't have a proximity sensor which this task can be coupled with like I have on my phone.
To just turn of the screen it would be
@!sendevent /dev/input/event1 1 107 1
!sendevent /dev/input/event1 1 107 0
the commands for the ADB process can be found in the OP and huge thanks to everyone who replied in the Tasker forums, but especially to Hypnotoad, credit to him. Thanks, I hope others find this useful.
Hey everyone,
So, FB blocked the messaging functionality on their mobile web page to force people to use the Messenger app.
I want to have Tasker completely kill the app when the device is not connected to the Internet and restart it when it connects again.
I know how to kill the app but I don't know how to restart it without it opening (basically, I want it to restart in the background).
I was thinking about intents or some shell command (am ?).
I have root & busybox.
EDIT: Not tested Tasker profile attached.
you need to , ectract this damn app like zip, after extract, you need to open the AndroidManifest.xml from the extracted folder, useing the RootExplorer.apk (this haves a text editor). Inside the AndroidManifest.xml, you will find the packagename, com.xxx.sss.etc, a list of the all activities are inside the tag <activity> on where you hcave to identify the initial activity that starts the app. For example, i took rootexplorer: i found the packagename: com.speedsoftware.rootexplorer, but is missing the MAIN component tagged in RootExplorer Activity, so, conclusing, by using the terminal emulator, or script executor builted in rootexplorer app or SManager i will type:
am start -n com.speedsoftware.rootexplorer/.RootExplorer
After this, the app starts
Legends:
am = application manager
start = am argument
-n = name of package
/.RootExplorer (token in example) = is the MainActivityComponent
I did never used tasker, but you can create bash shell script for call this command too.
Thata is all.
Sent from my XT687 using XDA Premium 4 mobile app
Dethfull said:
you need to , ectract this damn app like zip, after extract, you need to open the AndroidManifest.xml from the extracted folder, useing the RootExplorer.apk (this haves a text editor). Inside the AndroidManifest.xml, you will find the packagename, com.xxx.sss.etc, a list of the all activities are inside the tag <activity> on where you hcave to identify the initial activity that starts the app. For example, i took rootexplorer: i found the packagename: com.speedsoftware.rootexplorer, but is missing the MAIN component tagged in RootExplorer Activity, so, conclusing, by using the terminal emulator, or script executor builted in rootexplorer app or SManager i will type:
am start -n com.speedsoftware.rootexplorer/.RootExplorer
After this, the app starts
Legends:
am = application manager
start = am argument
-n = name of package
/.RootExplorer (token in example) = is the MainActivityComponent
I did never used tasker, but you can create bash shell script for call thppis command too.
Thata is all.
Sent from my XT687 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
I think I found main activity of Messenger: com.facebook.orca/.neue.MainActivity
Not tested profile attached.
[Question] How to use Tasker to connect and disconnect VPN with "OpenVPN for Android"
Hi folks,
in the past I used "OpenVPN Connect" to connect to my home network.
I found a guide how I can connect and disconnect the VPN automatically with a Tasker task (e.g. when I'm connected to a unknown wifi).
Now I switched to "OpenVPN for Android" for different reasons. I searched in the Internet for a similar soultion for Tasker, but I didn't found one.
I've managed to set up a task by myself to connect the VPN. But disconnecting doesn't work. aLogcat says "Denied" when I try to call the DisconnectVPN function/class.
I know that there's a app called "OpenVpn Tasker Plugin" which can do this for me. But I'm not a friend of "Apps-for-every-little-task". It would like to solve thiss with the Tasker actions itself.
Here are my tasks:
Connect VPN (works!)
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileNameROFILENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.LaunchVPN
Target:Activity
Disconnect VPN (doesn't work)
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileNameROFILENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.activities.DisconnectVPN
Target:Activity
The kill action to disconnect the VPN works, but the app restarts the VPN connection itself a few seconds later.
Has anyone an idea how to solve this?
Thank you!
Jas Man
This thread came to the right time
Now I'm working with shell commands (action "Run Shell") to run and stop the VPN.
Start VPN: am start -a android.intent.action.MAIN -n de.blinkt.openvpn/.LaunchVPN -e de.blinkt.openvpn.shortcutProfileName PROFILNAME
Stop VPN: am start -a android.intent.action.MAIN -n de.blinkt.openvpn/activities.DisconnectVPN
(must run with root)
I think the problem with the intents is, that I can't start them with root rights.
Last problem: disconnecting needs a confirmation to stop the VPN. I didn't found any option how I can disable this confirmation. Any idea?
Disconnecting by bypassing the notification can be done with this xposed plugin
http://repo.xposed.info/module/de.blinkt.vpndialogxposed
Mmmmh, I think this plugin confirmes only the VPN dialog which appeared in Android 4.x ("OpenVPN for Android tries to establish...blablabla").
And this is also a app which I have to install. Then I would prefer the "OpenVPN Tasker" plugin.
But regardless of this, thank you for your post.
if you want to do purely with Tasker, then I suggest you can also opt for the input tap function
Send Intent
Action: android.intent.action.VIEW
Cat: None
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: <Your VPN Name>
Package: net.openvpn.openvpn
Class: net.openvpn.openvpn.OpenVPNClient
Target: Activity
for OpenVPN Connect version 1.1.17
Click to expand...
Click to collapse
I hope this will help you.
vickylahkarbytes said:
if you want to do purely with Tasker, then I suggest you can also opt for the input tap function
Click to expand...
Click to collapse
That works but only if the screen is not locked. Therefore not usable for me. But also a nice idea.
haode said:
I hope this will help you.
Click to expand...
Click to collapse
That works only with "OpenVPN Connect". I use "OpenVPN for Android".
there is an open vpn tasker plugin the play store that may help you.
HatchetEgg said:
there is an open vpn tasker plugin the play store that may help you.
Click to expand...
Click to collapse
At the moment I use this app, but as I wrote in my first post I'm not a friend of "Apps-for-every-little-task". It would like to solve thiss with the Tasker actions itself.
Hi,
Thank you for all info posted. I have done the connect part. But for disconnect nothing works. I have tried both below solution.
Could you please give a help?
Code:
am start -a android.intent.action.MAIN -net.openvpn.openvpn/activities.DisconnectVPN
and
Code:
Send Intent
Action: android.intent.action.VIEW
Cat: None
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: <Your VPN Name>
Package: net.openvpn.openvpn
Class: net.openvpn.openvpn.DisconnectVPN
Target: Activity
Thank you!
amplatfus said:
Hi,
Thank you for all info posted. I have done the connect part. But for disconnect nothing works. I have tried both below solution.
Could you please give a help?
Code:
am start -a android.intent.action.MAIN -net.openvpn.openvpn/activities.DisconnectVPN
and
Code:
Send Intent
Action: android.intent.action.VIEW
Cat: None
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: <Your VPN Name>
Package: net.openvpn.openvpn
Class: net.openvpn.openvpn.DisconnectVPN
Target: Activity
Thank you!
Click to expand...
Click to collapse
Hello, you can just use the same code that you used to connect the VPN but, replace your VPN name with a bogus name. When it attempts to connect to the bogus VPN it will disconnect from the existing.
Hi, don't know if this is still relevant topic - but I've found a solution. But it requires root.
Just freeze/unfreeze openvpn app when needed - the command would be:
Run Shell pm disable de.blinkt.openvpn
or pm enable de.blinkt.openvpn
P.S. Running a fake vpn connection doesn't help unfortunately.
Author of the app put a solution together later in 2017: https://github.com/schwabe/ics-openvpn/issues/591
And after digging into the patch, the valid configuration should be
Code:
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileName:PROFIL ENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.api.DisconnectVPN
Target:Activity
I know this is an ancient question but I haven't seen anyone brought this up other than the GitHub issue. Hope it helps.
Here are my tasks:
Connect VPN (works!)
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileNameROFILENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.LaunchVPN
Target:Activity
Disconnect VPN (works!)
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileNameROFILENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.activities.api.DisconnectVPN
Target:Activity
Hope it will help you.
Frederick888 said:
Author of the app put a solution together later in 2017: https://github.com/schwabe/ics-openvpn/issues/591
And after digging into the patch, the valid configuration should be
Code:
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileName:PROFIL ENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.api.DisconnectVPN
Target:Activity
I know this is an ancient question but I haven't seen anyone brought this up other than the GitHub issue. Hope it helps.
Click to expand...
Click to collapse
Thank you for posting this :good:
Hi I'm looking for a similar guide for tasker for Samsungs S9 VPN comming from VpnCilla that unfortunately doesn't support L2TP/IPsec. Currently I believe I just need to know the right package name.
Looking forward for some new answer.
Samsung VPN
Hi,
I also swtiched VPN app only to Samsung own VPN .
How would I use this with tasker to auto turn on/off for certain apps?
Delete this.
"am start --user 0 -n de.blinkt.openvpn/.api.DisconnectVPN"
When creating this Task, I get a warning stating:
An external app tries to control OpenVPN for Android. The app requesting access cannot be determined. Allowing this app grants ALL apps access.
Is it not possible to only allow this task to access? I really don't want all apps to have access.
Hi,
I'm new to tasker, i downloaded it like a week ago. So any help will be apreciated.
I want to know if it is possible to make some contexts to trigger a profile (trigger contexts), while others not (they must be true for the profile to get activated, but they must not trigger it (state contexts)).
For example, i want to try this:
- When waze is active and at certain locations (like my home), run and intent to cleanly exit waze.
This is intented so when i arrive at destination, waze gets closed automatically. The problem arises if i'm at home and then open waze to drive somewhere, then it gets closed immediatly. Therefore, i'd like that only the location context triggers the profile.
Is this even possible? I want to create other profiles and task under this premise too.
Regards
Make a profile that only activates on location.
Make a second, separate profile for Waze running.
Method 1:
1. Give a custom name to the Waze profile (necessary), e.g. "Waze is Running".
2. Set the Waze profile to run a dummy task like "wait 10 milliseconds".
3. In the first step of your location task, add a Task > Stop > if %PACTIVE doesn't match regex .*Waze is Running.*
4. After this first step, the location task has to stop Waze.
Alternatively, instead of adding a Task > Stop, you can put the "if condition" in the step that closes Waze. Just change it from "doesn't match regex" to "matches regex".
Method 2:
1. Waze profile sets a global variable like %Waze to yes or 1 when Waze is running (enter task)
2. Waze profile clears the global variable when Waze quits (exit task)
3. Location profile checks %Waze instead of checking %PACTIVE
%PACTIVE contains a list of all currently active profiles, but you can only check for those profiles to which you've given a custom name.
Ok, thanks. I had already started with method 2, the only thing i was missing was the third step.
I think this is a task for the state event "Variable Set". As soon as an variable has changed, the task will be executed once. There is no exit task.
Example:
1. Create profiles which set your location to a variable, e.g. %Location
2. New Profile with event "Variable Set" and the variable %Location
3. If %Location change, execute Task which checks if %Location is equal Home or not. If Home, kill Waze. If not, do nothing.
4. When you are at home and start Waze, it will not get killed because the variable %Location has not changed. Therefore the profile will not be triggered. Only when you left home the variable changes and the task will be executed. When you come back to your home, the task will be executed again.
Thanks!! , this is more consistent and more easily applied to others profiles given the way I handle my profiles and tasks.