Skip to content

Instantly share code, notes, and snippets.

@maggocnx
Last active July 11, 2018 11:53
Show Gist options
  • Save maggocnx/b8d96327b8f126d4c886eaab9edd87a2 to your computer and use it in GitHub Desktop.
Save maggocnx/b8d96327b8f126d4c886eaab9edd87a2 to your computer and use it in GitHub Desktop.
Switch Network type
public void setEdge(View v){
setNetwork(1);
}
public void setLTE(View v){
setNetwork(7);
}
private void setNetwork(int networkType){
Settings.Global.putInt(getContentResolver(),"preferred_network_mode1", networkType);
toggleAiplaneMode(true);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
toggleAiplaneMode(false);
}
public void toggleAiplaneMode(boolean isEnabled){
Settings.Global.putInt(getContentResolver(),"airplane_mode_on", isEnabled ? 1 : 0);
sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment