[GUIDE][Difficulty: Beginner] Switch to 2G when Connected to WiFi

Search This thread

anzhaki

Senior Member
Sep 19, 2014
290
48
Xiaomi phone some time is kind of head-ache to such network things..................

If really free , build the following profile :

PROFILE CONTEXT : Mobile Network
Choose & check "2G"

PROFILE TASK :
Action 1. wait 5 seconds
Action 2. FLASH ( Text type in 2G )

so that if you mobile is having 2G environment , the screen will flashes " 2G ".

SPECIAL:
You can build as much profile as you like for 3G , 4G , Lte.
all you need to do is to create new profile and changing Profile name "3G" , "4G" so on ....
in profile context check "3G"
and , changing the task , the action 2 to say "3G" or "4G" so on....

edmond.

I see ......................

However , if you build as many as PROFILES respectively ( 2G , 3G , 4G LTE ...etc. )
The alert flash should "FLASHES" .

If I were you having your big difficulty now , I would first find free time & build all PROFILES ( note: these are all seperate PROFILES base on 2G , 3G , 4G & Lte ...etc. )

Then , manually press & switch to airplane mode. Switch back on to online mode.
The alert flash should at least flashes which GSM mode you are.

Edmond.
Hi sorry what is the purpose of doing those steps? For example if I am in 3g, if I toggle airplane mode then turn it off I will be in 3g again. I only added 3g and that is what happened, it showed me that I am in 3g. My problem is that using shell command to pass to 2g or 4g it doesn't work for some reasom.
 

eeeemc88

Member
May 15, 2018
18
2
Hi sorry what is the purpose of doing those steps? For example if I am in 3g, if I toggle airplane mode then turn it off I will be in 3g again. I only added 3g and that is what happened, it showed me that I am in 3g. My problem is that using shell command to pass to 2g or 4g it doesn't work for some reasom.

Hi, by switching airplane and back online mode. purpose if to use it to test if the flash is flashing or not.
Does it flash alert you when you turn back on on-line ?
( as suggested , create also such PROFIILE for 2G , 4G Lte ...etc. )

Another thing to make a "further" test is : in your "TASK" where switching to 2G or 3G or 4G .
Hit the play button ( i.e. in your 2G task )
Then, see if the flash is flashing you say "2G".

Do the same in your TASK of your 3G , hit the play button.
See if flashes you "3G"

So that you are doing step by step tesing where is wrong..... ( Hope you understand )

In other words, if 3G flashes but the 2G not flashes.
means, the TASK in 2G need modifiy in some point.
Rememeber the PROFILE I introduce you to create would not tell lie whether if it is really on 2G , it flashes 2G.
Or , if you phone really on 3G , it flash you 3G . You can see if by yourself .
Not relie on see it from setting .....etc.
( In Tasker , there is "Mobile Network" item for creating these PROFILES )

edmond.

---------- Post added at 02:27 AM ---------- Previous post was at 02:13 AM ----------

what is your task setting in your 3G ? ( see below the number after mode & mode1 )

setenforce permissive;
settings put global preferred_network_mode 1;
settings put global preferred_network_mode1 1;
setenforce enforcing

"CLONE" your 3G task to a few other new tasks
change the number 1 to 2
( and , do this on the other cloned task , change to 3 )
( and , do this on the other cloned task , change to 4 )
( and , do this on the other cloned task , change to 5 )
( and , do this on the other cloned task , change to 6 ) ...or 11 , 12

Then, in each of these task you created , hit play button to see the flash results.
( of course , you have to make the PROFILE of "Mobile Network" I introduce you )

edmond
 
  • Like
Reactions: anzhaki

anzhaki

Senior Member
Sep 19, 2014
290
48
Hi, by switching airplane and back online mode. purpose if to use it to test if the flash is flashing or not.
Does it flash alert you when you turn back on on-line ?
( as suggested , create also such PROFIILE for 2G , 4G Lte ...etc. )

Another thing to make a "further" test is : in your "TASK" where switching to 2G or 3G or 4G .
Hit the play button ( i.e. in your 2G task )
Then, see if the flash is flashing you say "2G".

Do the same in your TASK of your 3G , hit the play button.
See if flashes you "3G"

So that you are doing step by step tesing where is wrong..... ( Hope you understand )

In other words, if 3G flashes but the 2G not flashes.
means, the TASK in 2G need modifiy in some point.
Rememeber the PROFILE I introduce you to create would not tell lie whether if it is really on 2G , it flashes 2G.
Or , if you phone really on 3G , it flash you 3G . You can see if by yourself .
Not relie on see it from setting .....etc.
( In Tasker , there is "Mobile Network" item for creating these PROFILES )

edmond.

---------- Post added at 02:27 AM ---------- Previous post was at 02:13 AM ----------

what is your task setting in your 3G ? ( see below the number after mode & mode1 )

setenforce permissive;
settings put global preferred_network_mode 1;
settings put global preferred_network_mode1 1;
setenforce enforcing

"CLONE" your 3G task to a few other new tasks
change the number 1 to 2
( and , do this on the other cloned task , change to 3 )
( and , do this on the other cloned task , change to 4 )
( and , do this on the other cloned task , change to 5 )
( and , do this on the other cloned task , change to 6 ) ...or 11 , 12

Then, in each of these task you created , hit play button to see the flash results.
( of course , you have to make the PROFILE of "Mobile Network" I introduce you )

edmond

If I understand well you wanted me to test if I am really on 2g or 3g and that is not really a problem because I can see it from status bar and I'm not relying on what I see in settings. Anyway I did what you said and yes in all cases (2g, 3g and 4g) it flashed the right text.
About the settings I extracted the list of global variables and there are only preferred_network_mode and preferred_network_mode1.
I also know which number is 2g, 3g and 4g which are 1, 18 and 20 in my case and I'm quite sure about it because I extracted the values when I change network manually from settings.
The other thing is that only preferred_network_mode1 change when I switch network mode.
The problem is if I apply them from shell they work in settings menu but not really changing in my status bar probably because it expect a broadcast intent as the other guy said days before.
Sorry I'm not sure if I understood well what you mean because English is not my main language D:
 

eeeemc88

Member
May 15, 2018
18
2
The problem is if I apply them from shell they work in settings menu but not really changing in my status bar probably because it expect a broadcast intent as the other guy said days before.
Sorry I'm not sure if I understood well what you mean because English is not my main language D:

Note all above ............. ( Glad you builded all those PROFILES + it flashes you correctly 2G , 3G , 4G ..etc.)
so that , you know your tasker shell command in "task" are running correctly.
In my shell command , I checked mark the 'USE ROOT' ( only FYI )

I have not a clew now if you tell me your tasks are set right to all the 2G , 3G , 4G ...etc.
( that , you of course have press play button in the task and the flash appear to you )

In the beginning in my situation ., my PROFILE context is "DISPLAY STATE IS ON"
Task is :
Wait for 2 seconds.

Run Shell ( use root )
setenforce permissive;
settings put global preferred_network_mode 1;
settings put global preferred_network_mode1 1;
setenforce enforcing

so I will press power button ( Screen off ) , wait 2 seconds , press power button again ( Screen on ) ,
then to see the 2G flash come to you.

This is how I puzzle the 2G<==>3G profile before create successful profile ( lots of time/test)
Xiaomi phone I understand is some time diffcult as I said from yesterday in this thread.

edmond
 

Stoffl_

Senior Member
Jan 18, 2007
827
190
According to this
https://forum.xda-developers.com/mi-4c/general/preferred-network-type-t3322448

Code:
settings put global preferred_network_mode 1,20
Will set network mode to GSM only on MIUI.
I just checked and it works..only issue is that the setting doesn't get enforced automatically. I think we need an additional command to actually trigger it.
Much like when using shell to enable airplane mode..

https://android.stackexchange.com/q...in-lollipop-jellybean-using-adb/111513#111513

Now triggering airplane mode on/off will actually switch the network mode so I made this tasker task that will actually switch network mode to 2G when connected to Wifi on MIUI. It's a dirty workaround though... :/

Code:
#Enable&Force 2g Switch
settings put global preferred_network_mode 1,20;
settings put global airplane_mode_on 1;
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true;
#Disable Airplane Mode
settings put global airplane_mode_on 0;
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false;

This creates 2 additional issues though.

.) When phone finds a known wifi that's configured to autoconnect the task will run into a loop
.) When autoconnect isn't enable this will obviously not work

To switch back to 4G

Code:
#Enable&Force 4g Switch
settings put global preferred_network_mode 9,20;
settings put global airplane_mode_on 1;
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true;
#Disable Airplane Mode
settings put global airplane_mode_on 0;
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false;

Those 2 short scripts work when used via adb/terminal emulator.
The only other way to enforce a network mode switch I could find was through xposed/gravity box.. :(
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 17
    It's no secret that cellphone radios are among the biggest killers of your battery life. Among the worst offenders is the LTE radio, which is not as efficient as the 2G HSPA radio. Now, when you're connected to WiFi, no data is actually being transmitted however your phone still utilizes the LTE radio for connecting to your carrier's cell tower for calls/texts rather than the more efficient 2G HSPA radio. If you have poor LTE signal in your area, you can turn off the LTE radio while you're on WiFi to squeeze some extra battery life out of your phone.

    Prerequisites


    Instructions

    1. Create a new Profile and name it Toggle 2G/4G.
    2. Create a new State context, go to Net and choose Wifi Connected. Leave everything blank here.
    3. You can leave the task name blank, as it is unlikely you'll be using this elsewhere.
    2Cbu05j.jpg


    Now, you'll create the entry task

    1. Code --> Run Shell. These are the commands you'll need to run. Make sure you have "Use Root" checked!
      Code:
      setenforce permissive;
      svc data disable;
      setenforce enforcing
    2. Plugin --> Secure Settings. Expand the "Actions" dropdown and pick "Device Setting." For the Setting Table, pick "global." For the Setting Name, find "preferred_network_mode1" (make sure it's exactly this one, there are similar ones that don't work). Change Setting Value to 1 if you're on a GSM phone, or to 0 for WCDMA.

    Now, create the exit task by pressing on the Toggle 2G/4G profile then long-pressing on the entry task. Tasker will give you a few options here, but choose to "Add Exit Task."

    1. Code --> Run Shell. These are the commands you'll need to run. Make sure you have "Use Root" checked!
      Code:
      setenforce permissive;
      svc data enable;
      setenforce enforcing
    2. Plugin --> Secure Settings. Expand the "Actions" dropdown and pick "Device Setting." For the Setting Table, pick "global." For the Setting Name, find "preferred_network_mode1" (make sure it's exactly this one, there are similar ones that don't work). Change the Setting Value to 9 if on T-Mobile or 10 if you're on Sprint/Verizon.

    Exit out, and you're done! Now whenever you connect to WiFi, the LTE radio will be disabled, and when you disconnect it'll be enabled again! You'll still be able to receive calls and texts while on WiFi, of course, because the 2G HSPA radio is still on.
    6
    After a long search for doing this in nougat i found a thread on stackoverflow (question 37848059, but i'm not allowed to link because i made my account for this post).

    the trick is stopping and starting the ril-daemon (whatever it is :p)
    so the shell command for enabling only 2g is:

    setenforce permissive;
    settings put global preferred_network_mode 1;
    ettings put global preferred_network_mode1 1;
    stop ril-daemon;
    start ril-daemon;
    setenforce enforcing;

    Great work everybody on the forums by the way, i've solved a lot of my problems here.
    5
    if you do not have "1" this metod do not work.
    this is solution for you:
    https://play.google.com/store/apps/details?id=com.cygery.togglenetworktype
    2
    Its turn on/off mobile data.
    Not switch 2g-4g/LTE.
    2
    so, this method is not for you..
    Do you have xposed? Gravity box? Intelli3g?
    If not, instal this:
    https://play.google.com/store/apps/details?id=com.cygery.togglenetworktype
    Tasker support.