2011-09-09 9 views

Respuesta

5

EDIT: Esta solución también se apagará WiFi, Bluetooth, etc ...

Si desea apagar la radio solamente, creo que está relacionado con este tema: http://code.google.com/p/android/issues/detail?id=1065 Estoy muy pesimista sobre la búsqueda de una buena solución, pero curioso de ver otras respuestas.

Véase el artículo de blog Android: Controlling Airplane Mode,

// Toggle airplane mode. 
Settings.System.putInt(
     context.getContentResolver(), 
     Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); 

// Post an intent to reload. 
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); 
intent.putExtra("state", !isEnabled); 
sendBroadcast(intent); 

donde isEnabled es si el modo avión está activado o no.

No olvide que necesita el permiso WRITE_SETTINGS para hacerlo.

+0

1 buena solución –

+0

Cuando va a cambiar el teléfono al modo avión también se suprimirá wi-fi y bluetooth. No creo que sea lo que se espera. La tarea principal era suprimir solo la conexión GSM ... – barmaley

+0

yes.i ya lo intenté con airplanemode. Eso también deshabilitará el bluetooth. Pero quiero deshabilitar solo call y sms, ¿es posible? Deshabilité GPRS. ¿Hay algún método disponible? – Ram

5
/* Toggle airplane mode for 1 of the 4 allowed types 
* type allowed values: cell, wifi, bluetooth, nfc 
*/ 
private void changeRadioComponentEnabled(Context context, String type, boolean radio_component_enabled, boolean reset){  
     // now toggle airplane mode from on to off, or vice versa 
     Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, radio_component_enabled ? 0 : 1); 

     // now change system behavior so that only one component is turned off 
     // this also affects the future behavior of the system button for toggling air-plane mode. 
     // to reset it in order to maintain the system behavior, set reset to true, otherwise we lazily make sure mobile voice is always on 
     Settings.System.putString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_RADIOS, type); 

     // post an intent to reload so the menu button switches to the new state we set 
     Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); 
     intent.putExtra("state", radio_component_enabled ? false : true); 
     context.sendBroadcast(intent); 

     // revert to default system behavior or not 
     if (reset){ Settings.System.putString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_RADIOS, "cell,bluetooth,wifi,nfc"); } 
     // if reset to default is not chosen, always enable mobile cell at least 
     // but only if NOT changing the mobile connection... 
     else if (type.indexOf("cell") == 0) { Settings.System.putString(context.getContentResolver(), Settings.System.AIRPLANE_MODE_RADIOS, "cell");} 
}//end method 

naturalmente requieren este permiso android.permission.WRITE_SETTINGS, y para el bluetooth android.permission.BLUETOOTH_ADMIN. Para NFC, puede necesitar android.permission.NFC.

ediciones: muy modificada desde original, ya que en realidad estaba usando esto de una manera diferente en mi propia aplicación

+0

Mi teléfono también tiene wimax en Settings.System.AIRPLANE_MODE_RADIOS: "cell, bluetooth, wifi, nfc, wimax". ¡Eso es sorprendente porque este teléfono no es compatible con 4G WiMax! – pmont

Cuestiones relacionadas