Detect if mobile data is on

4,237 views
Skip to first unread message

Benny

unread,
Nov 6, 2013, 9:32:07 AM11/6/13
to tas...@googlegroups.com
Hi,

simple profil:

state: Display Off
    entry task: turn mobile data off
        settings: restore settings

in this case, mobile data is turned on again when the display is on.

So it seems to me that tasker knows whether mobile data is on or off. But I can't find an event or a state concerning the state of mobile data. There is a workaround to detect if mobile data is off: state -> not(or(2G,3G,4G)) but this only works fine when wifi is turned off.

My question: is there any solution to detect the mobile data status without turning wifi off ? Thanks =)



Wes Stacey

unread,
Nov 6, 2013, 11:36:02 AM11/6/13
to tas...@googlegroups.com
My method is to create 2 profiles one with the workaround you mentioned

State -> (or(2G,3G,4G)
enter task: set %MDATA to 1
          exit task: set %MDATA to 0 

State -> Wifi Connected 
Enter task: Set %WFC to 1
Exit Task: set %WFC to 0


Then when you can know if Wifi  and mobile data connection by a simple variable check. I use this to figure out if I actually have a data connection so on my tasks that use data i put in an if statement if(%WFC + %MDATA > 0) then i have a data connection.

Not sure if that helps you, it is hard to tell what you need to know without know how your going to use it. 

From what you have posted here i don't see any reason to know the status of the mobile radio, a simple turn off and turn on is fine. 

Benny

unread,
Nov 7, 2013, 10:53:44 AM11/7/13
to tas...@googlegroups.com
Your are right, a gave to little information ;)

The problem on my phone is, that "restore settings" doesn't work well: sometimes mobile data is turned on and sometimes it is not after the screen turned on. So i wanted to "manually" restore the settings. Similar to your solution, I wanted to store the status of mobile radio in a variable.

Now there is a second problem. I try to say it in your words in an example. Lets say, mobile data is on and wifi off, so %MDATA is set to 1 and %WFC to 0. Now you turn wifi on and connect, so %WFC is set to 1. But at the same time, %MDATA is set back to 0.

As long as you are wifi connected, Tasker will always give %MDATA the value 0, regardless of the status of mobile radio (%WFC + %MDATA is either 1 or 0, it can't be 2).

So my question is: Why does Tasker know that mobile data was turned on when you use "restore setting", but why is there no profile state to detect the status of mobile data.


Brandon Horwath

unread,
Nov 7, 2013, 12:32:59 PM11/7/13
to tas...@googlegroups.com
but why is there no profile state to detect the status of mobile data.

Context, state: Net, mobile data?

Wes Stacey

unread,
Nov 7, 2013, 12:51:39 PM11/7/13
to tas...@googlegroups.com
Brandon,

That tells you that you have a data connection not the state of the antenna. As Benny points out if you are connected to Wifi or are in area with not data service the Net->Mobile Data will register as false, whether the antenna is enabled for not. He wants a way to determine the status of the antenna not the connection.

-Wes

Brandon Horwath

unread,
Nov 7, 2013, 2:50:38 PM11/7/13
to tas...@googlegroups.com
Ah! I was thinking status of the connection.

i.e., if 2g do x, if 3g do y, etc.

Benny

unread,
Nov 8, 2013, 12:33:21 PM11/8/13
to tas...@googlegroups.com
Wes, you have totally understood my problem =) (thanks @ Brandon as well).

If anyone knew a solution, I would be happy :)


Rich D

unread,
Nov 8, 2013, 9:43:17 PM11/8/13
to tas...@googlegroups.com


> My question: is there any solution to detect the mobile data status without turning wifi off ? Thanks =)

Are you rooted?

You could have a look at shell; dumpsys telephony.registry

Benny

unread,
Nov 10, 2013, 2:38:35 PM11/10/13
to tas...@googlegroups.com
Hi Rich,

your answer sounds very promising, thanks!

Yes, I have a rooted device. Unfortunately, this commands returns me a ""Permission Denial: can't dump telephony.registry form pid = ....."

So I tried to install Tasker as a system app, but the problem remained. I guess, I didn't understand the solution that I found on the internet ;)

Maybe you know a documentation or some keywords I could look up ? That would be great :)


Matt R

unread,
Nov 10, 2013, 4:02:43 PM11/10/13
to tas...@googlegroups.com
Were you using the Tasker shell action? Did you check "use root"?

Matt

Benny

unread,
Nov 10, 2013, 4:15:37 PM11/10/13
to tas...@googlegroups.com
Hi Matt,

how embarrassing, of course I didn't check "use root" (yes, I was using the Tasker shell action)

Now it works perfectly :))))

THANKS to all of you !! :)




Matt R

unread,
Feb 26, 2014, 8:34:15 PM2/26/14
to tas...@googlegroups.com
Just bringing this up as something I just found.  On my device at least, I can do the shell command (with root):

settings get global mobile_data

and it will return 1 (mobile data on) or 0 (mobile data off).  There are other settings listed in the /system/etc/settings.xml that it can pull too.

Matt

Michele Possamai

unread,
Apr 6, 2014, 10:05:24 PM4/6/14
to tas...@googlegroups.com
So... Still no solution for non-rooted android?
I don't get it.. How hard can it be?

Matt R

unread,
Apr 7, 2014, 3:41:57 AM4/7/14
to tas...@googlegroups.com
You can try the new app mentioned here: https://groups.google.com/d/topic/tasker/sRJKsaulGVg/discussion

It doesn't look like it requires root and it sounds like it does the same thing that I mentioned using the system settings.

Matt

Dion GeBorde

unread,
Jun 5, 2014, 10:44:20 PM6/5/14
to tas...@googlegroups.com
This thread, and particularly the System Settings for Tasker solution, was exactly what I was looking for. Thanks everyone!

But Benny, looking at your notation really got me curious. You are writing an "or" condition into the Tasker profile's contexts. How do you do that in practice, as Tasker only supports "and" in the contexts?

Brandon Horwath

unread,
Jun 5, 2014, 11:34:08 PM6/5/14
to tas...@googlegroups.com
How do you do that in practice, as Tasker only supports "and" in the contexts?

Latest version also supports 'or', 'Xor', (or) high priority, and (and) high priority.

Pent

unread,
Jun 6, 2014, 2:43:39 AM6/6/14
to tas...@googlegroups.com
In the next Tasker version (4.4) there's an action Net / Test which lets you test the mobile data setting.

Pen

Dion GeBorde

unread,
Jun 6, 2014, 11:29:01 AM6/6/14
to tas...@googlegroups.com

Brandon, are you referring to contexts here? Because I have version 4.3u4m for Android 4+ and I don't see any options for that. But those filters are in the variable and Task areas for sure.

On Jun 5, 2014 8:34 PM, "Brandon Horwath" <brandon...@gmail.com> wrote:
How do you do that in practice, as Tasker only supports "and" in the contexts?

Latest version also supports 'or', 'Xor', (or) high priority, and (and) high priority.

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/XuFmkICjVsA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Matt R

unread,
Jun 6, 2014, 12:16:59 PM6/6/14
to tas...@googlegroups.com
They can only be used in the variable value context.

Matt

Brandon Horwath

unread,
Jun 6, 2014, 2:16:43 PM6/6/14
to tas...@googlegroups.com
Both.

Utilized in task, i.e. %var ~ some OR %var ~ thing

Utilized in condition, i.e. %Var ~ something OR %Var ~ else

Dion GeBorde

unread,
Jun 6, 2014, 2:52:07 PM6/6/14
to tas...@googlegroups.com
First of all, thanks everybody for chiming in. Really appreciate the spirit of support.

Pen, I'd definitely be looking forward to that! Although in fact, David White's System Settings for Tasker is working flawlessly for me, so the need is no longer urgent. :-)

And Brandon, I definitely get what you're saying, but as Matt mentioned, they can only be used in variables, wherever those variables may be used, which of course includes the Variables: Variable Value under the State context. And if that's what Benny did, then that explains it.

It's just that the way he configured his code [ state -> not(or(2G,3G,4G)) ] made it look to me like he was not using a variable, but the mobile data settings under Net in the State context.

Only if that's the case am I curious to know how he did it. I did read one person's very creative approach to getting to OR using NOT and AND conditions, as:

( A or B ) = NOT ((NOT A) AND (NOT B))

So, having seen that, I simply wondered if Benny had found a magic formula for simulating a multiple-condition OR without using variables.

Got one of those Brandon? Benny? Bueller? ;-)



On Wednesday, November 6, 2013 6:32:07 AM UTC-8, Benny wrote:

Matt R

unread,
Jun 6, 2014, 3:59:32 PM6/6/14
to tas...@googlegroups.com
Getting "not(or(2G,3G,4G))" is just a matter of checking the boxes in the state -> net -> mobile data, including the invert box (which gives you the "not").

Matt

Dion GeBorde

unread,
Jun 6, 2014, 6:53:39 PM6/6/14
to tas...@googlegroups.com
I started to write one response, but as I thought it through, I realized you are right. "Not(or(X,Y,Z))" means not any of them. Just check all the boxes and invert.

I got myself thinking about checking all the boxes, which I assume Tasker sees as an AND condition (context is true when ALL data networks are enabled). It's the invert that makes it OR.

Puzzle solved! Thanks Matt.
Reply all
Reply to author
Forward
0 new messages