Go Back   Android Forums > Android Discussion > Android Applications > Tasker

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old May 1st, 2013, 06:08 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: May 2013
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default WiFi control when launching an app

Hi all,

I'm trying to create a simple procedure using TASKER that basically turns on Wifi, waits a few seconds, then runs an app that requires network access.
My problem is that I also want to turn off Wifi ONLY when the app closes but unfortunately have so far found no way to do so.

Basically:

TASK: WiFi ON
TASK: WAIT (a few secs)
TASK: LOAD app
TASK: WiFi Off

However, as soon as the app loads and starts running, WiFi is immediately turned off.

Does anyone know of a way to somehow detect that the app is running and prevent the WiFi Off command from executing UNTIL the app closes ?

The reason that I have to manually turn WiFi ON is because some of my apps generate error messages if network access is unavailable when the app starts.

Thanks

skawka is offline  
Reply With Quote
sponsored links
Old May 31st, 2013, 12:21 PM   #2 (permalink)
New Member
 
Join Date: May 2013
Gender: Male
Posts: 7
 
Device(s): Motorola RAZR HD XT925 Samsung Galaxy S4 I9500
Carrier: Telstra

Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by skawka View Post
Hi all,

I'm trying to create a simple procedure using TASKER that basically turns on Wifi, waits a few seconds, then runs an app that requires network access.
My problem is that I also want to turn off Wifi ONLY when the app closes but unfortunately have so far found no way to do so.

Basically:

TASK: WiFi ON
TASK: WAIT (a few secs)
TASK: LOAD app
TASK: WiFi Off

However, as soon as the app loads and starts running, WiFi is immediately turned off.

Does anyone know of a way to somehow detect that the app is running and prevent the WiFi Off command from executing UNTIL the app closes ?

The reason that I have to manually turn WiFi ON is because some of my apps generate error messages if network access is unavailable when the app starts.

Thanks
Quite a late reply but I just found this Tasker section and signed up to the forum.

One way to do it is at the shell if you're rooted.
After Load App, you can run a shell script that checks every few seconds to see if the app is still running, and when it isn't it exits. How Android allows this is differant on every phone. I've used shell scripts on the phone that were useful, select scripts and shell, then without the quotes "sh /path/to/the/script" and with this failed I used sl4a to run it, however this also doesn't work well sometimes in which case everything has to go into a single line at script->run shell with semicolons separating each command. If you're familiar with sh or bash (sh has more limitations but is for the most part compatible), then you would have a starting point for it. If you're good at some other language and sl4a runs on your phone then that's just as well.

In any case, it takes a lot of poking around to find exactly what you need, for example you don't want it to close when its backgrounded, but to get you started, this command run at the shell using adb will tell you what the forground process is
[HIGH]dumpsys activity top | grep '^TASK.*' | cut -d ' ' -f2[/HIGH]I got that from here http://forum.xda-developers.com/showpost.php?p=30175170&postcount=3 under the section "Force stopping an application" Its a snippet of the command t0 force stop whats in the foreground window. Its the part that shows what's in the foreground window.
Note that not everything on that page applies globaly to Android and some of the info on the page is only covered under ICS and possibly only the SGS2 but this command has remained the same for me across 3 upgrades and 3 different phones and on AOSP ROMs as well.

From there you can use dumpsys and direct into a file while your app is forgrounded, backgrounded, or closed or running as a service and get a grasp on what exactly you need to look for, then set up a shell script that looks something like this, which I did for Facebook

[HIGH]#!/system/bin/sh

sleep 2
x="something"
while [ "$x" != "" ] ; do
x=`dumpsys activity | grep com.facebook.katana/.LoginActivity`
sleep 2
done[/HIGH]If you can't call the script from tasker, it looks a little differant behind do and then statements when you set it up as a one liner in tasker, so the above would look like this

[HIGH]sleep2 ; x="something" ; while [ "$x" != "" ] ; do x=`dumpsys activity | grep com.facebook.katana/.LoginActivity` ; sleep 2 ; done[/HIGH]Note that the end of line after do in the script implies a semicolon but that it isn't used when running it all as a one liner. Its the same if you use if [ ] ; then .... you wouldn't put a semicolon after then.
The initial sleep 2 at the beginning is optional as you're already using Wait in Tasker to achieve the same thing.

If you tick continue after error, this will not work as the task will not hang until the loop in the shell exits, but move on to the next step in the task. You do want to have use root ticked though.

There may well be a much easier way than this that's built into the Tasker app, but this is how I've been doing this sort of thing and haven't found any other answers.

Good luck. I hope to find a better answer at some point.


As an afterthought, I've never tried it, but if there's a way to set up a state condition for when an app runs, you can probably have enter and exit tasks that toggle the wifi... I'm guessing that the lack of prior reply suggests this isn't possible though. It would be a hit on your battery unless you could toggle that state profile in conjunction with the task... in any case I doubt its possible. The thins I've set up are for unfreezing an app that usually runs as a service, running it, then freezing it down again on exit, so this is where my example at the shell comes in, in relation to your problem.
PantsDownJedi is offline  
Last edited by PantsDownJedi; May 31st, 2013 at 12:44 PM. Reason: Editing is the new "Awesome"
Reply With Quote
Old June 1st, 2013, 03:39 AM   #3 (permalink)
Junior Member
 
Join Date: May 2013
Posts: 27
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 4 Times in 3 Posts
Default

There should be 2 easier ways to do that.

The simplest way is to turn the problem around. Why not create a profile that will switch the Wi-Fi on when the app is running:

Profile: BBC News Running
Application > BBC News

Task: Switch Wi-Fi On
Net > WiFi: on

Exit Task: Switch Wi-Fi Off
Net > WiFi: off




Now I agree that this is not exactly what the OP is asking for. He may want the Wi-Fi to be available before the app is running. So what about:

Profile: BBC News Running
Application > BBC News

Task: BBC News Started
Variables . Variable Set: %BbcNewsRunning to yes

Exit Task: BBC News Stopped
Variables . Variable Set: %BbcNewsRunning to no


Op task:
(...)
Net > WiFi: on
Task > Wait: 10 seconds
App > Load App: BBC News
Task > Wait Until: 10 seconds, Until %BbcNewsRunning !~ yes
Net > WiFi: off
(...)
WarriusZero is offline  
Last edited by WarriusZero; June 1st, 2013 at 03:56 AM. Reason: because I'm worth it
Reply With Quote
Reply


Go Back   Android Forums > Android Discussion > Android Applications > Tasker
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:41 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.