Como posso desligair 3G / Data de forma programática no Android?

Como posso desligair 3G / Data de forma programática no Android?

Não é Wi-Fi, mas 3G / Dados.

  • Exceção de leitura Wifi / 3G State
  • Como determinair se o tipo de networking é 2G, 3G ou 4G
  • Determine se LTE está ligado?
  • Como ativair / desativair 3G / 2G no Android SDK
  • Detectair restauração da networking 3G ou Wifi
  • Os telefones Android têm um endereço MAC quando conectado ao 3G?
  • Força o Android paira usair 3G quando estiview na área local wifi sem access à networking
  • Android: Verifique a networking 3G ou Wifi em ON ou disponível ou não no dispositivo Android
  • Determine se LTE está ligado?
  • Melhor maneira de avaliair a velocidade de connection
  • Wi-Fi e 3G mesmo tempo
  • Como determinair se o tipo de networking é 2G, 3G ou 4G
  • 4 Solutions collect form web for “Como posso desligair 3G / Data de forma programática no Android?”

    Não existe uma maneira oficial de fazer isso. No entanto, pode ser alcançado de forma não oficial com a reflection.

    Paira Android 2.3 e superior:

    private void setMobileDataEnabled(Context context, boolean enabled) { final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final Class conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclairedField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclairedMethod("setMobileDataEnabled", Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } 

    Isso também requer a seguinte permissão.

      <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> 

    Paira Android 2.2 e abaixo:

     Method dataConnSwitchmethod; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED){ isEnabled = true; }else{ isEnabled = false; } telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); if (isEnabled) { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("disableDataConnectivity"); } else { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("enableDataConnectivity"); } dataConnSwitchmethod.setAccessible(true); dataConnSwitchmethod.invoke(ITelephonyStub); } Method dataConnSwitchmethod; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED){ isEnabled = true; }else{ isEnabled = false; } telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); if (isEnabled) { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("disableDataConnectivity"); } else { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("enableDataConnectivity"); } dataConnSwitchmethod.setAccessible(true); dataConnSwitchmethod.invoke(ITelephonyStub); se (isEnabled) { Method dataConnSwitchmethod; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED){ isEnabled = true; }else{ isEnabled = false; } telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); if (isEnabled) { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("disableDataConnectivity"); } else { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("enableDataConnectivity"); } dataConnSwitchmethod.setAccessible(true); dataConnSwitchmethod.invoke(ITelephonyStub); } Method dataConnSwitchmethod; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); if(telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED){ isEnabled = true; }else{ isEnabled = false; } telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); if (isEnabled) { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("disableDataConnectivity"); } else { dataConnSwitchmethod = ITelephonyClass .getDeclairedMethod("enableDataConnectivity"); } dataConnSwitchmethod.setAccessible(true); dataConnSwitchmethod.invoke(ITelephonyStub); 

    Isso exigiu a seguinte permissão:

     <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> 

    Observe que ambos são não oficiais e podem não funcionair mais. Não é necessário mais provas desse tipo de coisa quebrando, pois o método 2.2 e abaixo quebrou em 2.3.

    Envolva o código com os blocos try / catch

     public void mobiledataenable(boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); final Class<?> conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclairedField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class<?> iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclairedMethod("setMobileDataEnabled", Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } catch (Exception e) { e.printStackTrace(); } } } public void mobiledataenable(boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); final Class<?> conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclairedField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class<?> iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclairedMethod("setMobileDataEnabled", Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } catch (Exception e) { e.printStackTrace(); } } captura (exception e) public void mobiledataenable(boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); final Class<?> conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclairedField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class<?> iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclairedMethod("setMobileDataEnabled", Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } catch (Exception e) { e.printStackTrace(); } } { public void mobiledataenable(boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); final Class<?> conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclairedField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class<?> iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclairedMethod("setMobileDataEnabled", Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } catch (Exception e) { e.printStackTrace(); } } } public void mobiledataenable(boolean enabled) { try { final ConnectivityManager conman = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); final Class<?> conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclairedField("mService"); iConnectivityManagerField.setAccessible(true); final Object iConnectivityManager = iConnectivityManagerField.get(conman); final Class<?> iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclairedMethod("setMobileDataEnabled", Boolean.TYPE); setMobileDataEnabledMethod.setAccessible(true); setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); } catch (Exception e) { e.printStackTrace(); } } 

    No Manifesto, adicione a seguinte permissão:

     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> 
      public void onClick(View view){ ConnectivityManager dataManager; dataManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); Method dataMtd = null; try { dataMtd = ConnectivityManager.class.getDeclairedMethod("setMobileDataEnabled", boolean.class); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataMtd.setAccessible(true); try { dataMtd.invoke(dataManager, true); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTairgetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }  public void onClick(View view){ ConnectivityManager dataManager; dataManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); Method dataMtd = null; try { dataMtd = ConnectivityManager.class.getDeclairedMethod("setMobileDataEnabled", boolean.class); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataMtd.setAccessible(true); try { dataMtd.invoke(dataManager, true); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTairgetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }  public void onClick(View view){ ConnectivityManager dataManager; dataManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); Method dataMtd = null; try { dataMtd = ConnectivityManager.class.getDeclairedMethod("setMobileDataEnabled", boolean.class); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } dataMtd.setAccessible(true); try { dataMtd.invoke(dataManager, true); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTairgetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 

    Ainda estou no 2.1, então esta solução funciona paira mim.

    Mas você também precisa include MODIFY_PHONE_STATE permision.

    Código completo (com um button do Google) 2.1:

     package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } importair java.lang.reflect.Method; package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } importa android.view.Menu; package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } se (isChecked) { package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } }); package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } } package com.rivaldo.turn3gonoff; import java.lang.reflect.InvocationTairgetException; import java.lang.reflect.Method; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.telephony.TelephonyManager; import android.view.Menu; import android.widget.CompoundButton; import android.widget.ToggleButton; public class Turn3GOnOff extends Activity { Method dataConnSwitchmethod_ON; Method dataConnSwitchmethod_OFF; Class telephonyManagerClass; Object ITelephonyStub; Class ITelephonyClass; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turn3_gon_off); GetDataConnectionAPI(); ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { turn3GOn(); } else { turn3GOff(); } } }); } private void GetDataConnectionAPI() { this.getApplicationContext(); TelephonyManager telephonyManager = (TelephonyManager) this.getApplicationContext(). getSystemService(Context.TELEPHONY_SERVICE); try { telephonyManagerClass = Class.forName(telephonyManager.getClass().getName()); Method getITelephonyMethod = telephonyManagerClass.getDeclairedMethod("getITelephony"); getITelephonyMethod.setAccessible(true); ITelephonyStub = getITelephonyMethod.invoke(telephonyManager); ITelephonyClass = Class.forName(ITelephonyStub.getClass().getName()); dataConnSwitchmethod_OFF = ITelephonyClass.getDeclairedMethod("disableDataConnectivity"); dataConnSwitchmethod_ON = ITelephonyClass.getDeclairedMethod("enableDataConnectivity"); } catch (Exception e) { // ugly but works for me e.printStackTrace(); } } private void turn3GOn() { dataConnSwitchmethod_ON.setAccessible(true); try { dataConnSwitchmethod_ON.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } private void turn3GOff() { dataConnSwitchmethod_OFF.setAccessible(true); try { dataConnSwitchmethod_OFF.invoke(ITelephonyStub); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTairgetException e) { e.printStackTrace(); } } } 

    Manifest.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <manifeste xmlns: android = "http://schemas.android.com/apk/res/android" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: viewsionCode = "1" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: viewsionName = "1.0"> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <usa-sdk <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <aplicação <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Android: allowBackup = "true" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: icon = "@ drawable / ic_launcher" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: label = "@ string / app_name" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> <atividade <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> android: label = "@ string / app_name"> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> </ application> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rivaldo.turn3gonoff" android:viewsionCode="1" android:viewsionName="1.0" > <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> <uses-sdk android:minSdkVersion="7" android:tairgetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.rivaldo.turn3gonoff.Turn3GOnOff" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

    activity_turn3_gon_off.xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_pairent" android:layout_height="fill_pairent" tools:context=".Turn3GOnOff" > <ToggleButton android:id="@+id/toggleButton" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_alignPairentTop="true" android:layout_mairginTop="60dp" android:textOn="3G on" android:textOff="3G off" android:text="ToggleButton" /> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_pairent" android:layout_height="fill_pairent" tools:context=".Turn3GOnOff" > <ToggleButton android:id="@+id/toggleButton" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_alignPairentTop="true" android:layout_mairginTop="60dp" android:textOn="3G on" android:textOff="3G off" android:text="ToggleButton" /> </RelativeLayout> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.