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

Search This thread

MishaalRahman

Editor in Chief
Nov 2, 2015
1,039
2,123
www.xda-developers.com
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.
 
Last edited:

frrancuz.

Senior Member
Feb 18, 2012
137
40
Do you tested it?

SS -> run shell: settings put global preferred_network_mode XX
Its the same.

On my phone preffered network wont changed. Need reboot.

[Sorry for the mistakes.
I do not know English well.
I use Google translator.]
 

MishaalRahman

Editor in Chief
Nov 2, 2015
1,039
2,123
www.xda-developers.com
Do you tested it?

SS -> run shell: settings put global preferred_network_mode XX
Its the same.

On my phone preffered network wont changed. Need reboot.

[Sorry for the mistakes.
I do not know English well.
I use Google translator.]

Yes, I tested it. Make sure it's EXACTLY this: preferred_network_mode1. Note the 1 at the end. The other ones don't work!
 

frrancuz.

Senior Member
Feb 18, 2012
137
40
I have not "preferred_network_mode1" on my global settings, only "preferred_network_mode". When I change network mode the number change - 1 for 2g, 11 for LTE.

So?
This guide is not for all?
 
  • Like
Reactions: arbolarc

frrancuz.

Senior Member
Feb 18, 2012
137
40
1. Set manual 2g

Run shell: sqlite3 /data/data/com.android.providers.settings/databases/settings.db "SELECT name, value FROM global;"

Store matvhes in 2g. txt

2. Set LTE/4g
Run shell
Store matches in 4g.txt

Check what do you have in "network-preffered"
 
  • Like
Reactions: [email protected]

enskje

Senior Member
Jan 13, 2012
844
161
Google Pixel 4
Google Pixel 4 XL
1. Set manual 2g

Run shell: sqlite3 /data/data/com.android.providers.settings/databases/settings.db "SELECT name, value FROM global;"

Store matvhes in 2g. txt

2. Set LTE/4g
Run shell
Store matches in 4g.txt

Check what do you have in "network-preffered"
ok, thanks. now I can't find network_preffered1... only network_prefered.

Sent from my ALE-L21 using Tapatalk
 

MishaalRahman

Editor in Chief
Nov 2, 2015
1,039
2,123
www.xda-developers.com
1. Set manual 2g

Run shell: sqlite3 /data/data/com.android.providers.settings/databases/settings.db "SELECT name, value FROM global;"

Store matvhes in 2g. txt

2. Set LTE/4g
Run shell
Store matches in 4g.txt

Check what do you have in "network-preffered"

Good idea on using SQLite. For anyone that can't get it working using his method, try downloading the Tasker SQLite Plugin.
 

arbolarc

Member
Jan 8, 2015
39
3
I couldnt get the network to turn back on when my wifi turns off :/

---------- Post added at 11:43 PM ---------- Previous post was at 11:39 PM ----------

I have not "preferred_network_mode1" on my global settings, only "preferred_network_mode". When I change network mode the number change - 1 for 2g, 11 for LTE.

So?
This guide is not for all?
Thanks! I got the network to turn on yay
 

gub

Senior Member
Apr 18, 2006
81
31
Samsung Galaxy Note 4
Did you measure the battery consumption of 4G vs 3G vs 2G?
Disabling mobile data will clearly improve your battery life, however, unless you have poor 4G and good 2G and the phone insists on using 4G, I don't see how disabling 4G can be an improvement.
First of all, because 4G is faster, you will spend a shorter amount of time in high power transmit mode for a given number of bytes transferred. Additionally, newer standards typically improve power efficiency even in low power / standby modes.
If disabling 4G really improves battery life, maybe it is specific to your location. In this case, it may be better to set your script to trigger only on a specific WiFi network, or in a specific location.
 

MishaalRahman

Editor in Chief
Nov 2, 2015
1,039
2,123
www.xda-developers.com
Did you measure the battery consumption of 4G vs 3G vs 2G?
Disabling mobile data will clearly improve your battery life, however, unless you have poor 4G and good 2G and the phone insists on using 4G, I don't see how disabling 4G can be an improvement.
First of all, because 4G is faster, you will spend a shorter amount of time in high power transmit mode for a given number of bytes transferred. Additionally, newer standards typically improve power efficiency even in low power / standby modes.
If disabling 4G really improves battery life, maybe it is specific to your location. In this case, it may be better to set your script to trigger only on a specific WiFi network, or in a specific location.

This post goes into detail about the effect on battery life from 4G vs 2G: https://www.reddit.com/r/Android/comments/3z8guc/psa_one_of_the_biggest_battery_life_killers_is/
 

jlc403

Senior Member
Nov 15, 2005
114
20
Anyone tried this on Sprint S5? Love the idea. Just wondering if anyone else has experimented before I implement.
Thanks!
Josh
 

powerdoesntrun

Senior Member
Nov 20, 2010
309
37
Is there any way to get this to work with Project Fi? I've been trying to make this work so it will switch to GSM or CDMA, depending on whether I'm connected to T-Mobile or Sprint, but I haven't quite figured it out.
 

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.