Mobile data trigger

Qarboz

Well-known member
Hi everyone.
I need a trigger that is activated when mobile data is turned on or off. Macroadroid does not seem to have it; I tried with the System Setting Change trigger using the {setting_global=mobile_data} value (also {setting_global=mobile_data1} and {setting_global=mobile_data2}) but it doesn't fire. I thought about the Logcat Message trigger, but I don't know which key to use; I used the Capture Logcat messages button selecting only the Radio flag, but many results come out and I couldn't find the useful one.
Advice on how to proceed?
MacroDroid 5.35.12, Android 12 rooted
 

Endercraft

Moderator (& bug finder :D)
I thought of that too, I wonder why there is a constraint but no trigger ?
You could try using connectivity triggers with mobile data constraints but I don't think it would work fine.
I guess the best workaround would be to check the constraint status repeatedly in a loop, use it to set a boolean global var then use the variable change trigger on that.
 

sampleuserhere

Active member
I used the Capture Logcat messages button selecting only the Radio flag, but many results come out and I couldn't find the useful one.
Advice on how to proceed?

Try the following tags.

Code:
TrafficManageService
ConnectivityManager
DataUsageController


I thought of that too, I wonder why there is a constraint but no trigger ?
The constraints possibly queries the mobile state each time the trigger about to fire the actions.
 

dhj49er

Well-known member
Hi everyone.
I need a trigger that is activated when mobile data is turned on or off. Macroadroid does not seem to have it; I tried with the System Setting Change trigger using the {setting_global=mobile_data} value (also {setting_global=mobile_data1} and {setting_global=mobile_data2}) but it doesn't fire. I thought about the Logcat Message trigger, but I don't know which key to use; I used the Capture Logcat messages button selecting only the Radio flag, but many results come out and I couldn't find the useful one.
Advice on how to proceed?
MacroDroid 5.35.12, Android 12 rooted
I use the Data available trigger

See the attached macro.

I use this when mobile data is turned on or off

Is this what you are trying to do?
 

Attachments

  • Screenshot_20230827_155919_MacroDroid.jpg
    Screenshot_20230827_155919_MacroDroid.jpg
    413.8 KB · Views: 28

dhj49er

Well-known member
@dhj49er the data available trigger triggers whenever you have any type of connection active, not just mobile data unfortunately.
Yes....but look at the macro.

I have a Boolean variable WifiConnected which is true when WiFi is connected and false when WiFi is disconnected.

The WifiConnected false prevents the macro triggering as WifiConnected is set true as the first action in another macro triggered by WiFi Connected.
 

Endercraft

Moderator (& bug finder :D)
Yes....but look at the macro.

I have a Boolean variable WifiConnected which is true when WiFi is connected and false when WiFi is disconnected.

The WifiConnected false prevents the macro triggering as WifiConnected is set true as the first action in another macro triggered by WiFi Connected.
Indeed, I missed that part. Although it will not work if I toggle on mobile data when wifi is connected, it will only change if you are connected through mobile data - but that may be sufficient for most cases.
 

dhj49er

Well-known member
Indeed, I missed that part. Although it will not work if I toggle on mobile data when wifi is connected, it will only change if you are connected through mobile data - but that may be sufficient for most cases.
That is my use case.
I never have WiFi on and try to turn on mobile data.
 

Qarboz

Well-known member
Thanks everyone for the replies ;)


I thought of that too, I wonder why there is a constraint but no trigger ?
You could try using connectivity triggers with mobile data constraints but I don't think it would work fine.
I guess the best workaround would be to check the constraint status repeatedly in a loop, use it to set a boolean global var then use the variable change trigger on that.
I've thought about it, but it will be the last chance if I can't do it any other way


Try the following tags.

Code:
TrafficManageService
ConnectivityManager
DataUsageController



The constraints possibly queries the mobile state each time the trigger about to fire the actions.
Thanks for the strings, I'll try ;)


That is my use case.
I never have WiFi on and try to turn on mobile data.
Not my use case; I normally have wifi and data turned on, it wouldn't work for me. Thanks anyway for the answer
 

dhj49er

Well-known member
I think changing the constraint in my macro might work with WiFi connected.

Change the constraint to another Boolean variable EnableMobileData true.

In your wifi connected and WiFi disconnected macro(s) add the following.

First action in this or these macros is set EnableMobileData False - this prevents the mobile data macro from running.
Later on in this or these macros or after a 50ms wait add action set EnableMobiledata True - this will allow the mobile data macro to run when WiFi is connected.
 

Qarboz

Well-known member
Try the following tags.

Code:
TrafficManageService
ConnectivityManager
DataUsageController



The constraints possibly queries the mobile state each time the trigger about to fire the actions.
I tried ConnectivityManager but it doesn't work if I turn on/off mobile data from android menu. I couldn't find the other items...
However, after searching further, I found DataEnabledSettings
[1]onUserMobileDataStateChanged dds=1 mSubId=1 enabled=true

and
DataEnabledSettings
[1]onUserMobileDataStateChanged dds=1 mSubId=1 enabled=false

that seems to work fine. I'm monitoring it over the next few days to see if it's okay


I think changing the constraint in my macro might work with WiFi connected.

Change the constraint to another Boolean variable EnableMobileData true.

In your wifi connected and WiFi disconnected macro(s) add the following.

First action in this or these macros is set EnableMobileData False - this prevents the mobile data macro from running.
Later on in this or these macros or after a 50ms wait add action set EnableMobiledata True - this will allow the mobile data macro to run when WiFi is connected.
If I turn off/on mobile data via the Android menu it doesn't work if WiFi is connected; even if I turn on the mobile data without signal the trigger [on] does not fire, or the trigger [off] fires if there is no signal although the mobile data switch is on.
 

sampleuserhere

Active member
DataEnabledSettings
[1]onUserMobileDataStateChanged dds=1 mSubId=1 enabled=false

that seems to work fine. I'm monitoring it over the next few days to see if it's okay.

That should do it I think, monitoring QuickTike entry should be foolproof too.

You could query the mobile data status as well to make the result even more reliable. You can do it by running the following line via Shell Script.

Code:
dumpsys telephony.registry | grep "mUserMobileDataState=" | awk -F '=' '{print $2}' | sed ':a;N;$!ba;s/\n/,/g' | sed "s/.*/[\0]/g"

Returns [ boolean, boolean ] if your phone supports two SIM cards.

Don't forget to check rooted option or you could always grant DUMP permission for Macrodroid to run the line on non-rooted device.[/CODE]
 

Pepy

Member
What you entered in the System settings change trigger is the value of the setting when what you need is the name of it.
 

Attachments

  • Test.png
    Test.png
    92.8 KB · Views: 19
Last edited:
Top