2011-09-09 8 views

risposta

5

EDIT: Questa soluzione si spegnerà WiFi, Bluetooth, ecc ...

Se si desidera disattivare solo la radio, penso che sia legato a questo problema: http://code.google.com/p/android/issues/detail?id=1065 Sono molto pessimista di trovare una buona soluzione, ma curioso di vedere altre risposte.

vedere l'articolo del 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); 

dove isEnabled è se la modalità aereo è abilitato o meno.

Non dimenticare che è necessario il permesso WRITE_SETTINGS per farlo.

+0

+1 buona soluzione –

+0

Quando si passa il telefono in modalità aereo si sarà anche sopprimere wi-fi e bluetooth. Non penso che sia ciò che è previsto. Il compito primario era quello di sopprimere solo la connessione GSM ... – barmaley

+0

sì, ho già provato con airplanemode. Ciò disabiliterà anche il Bluetooth.ma voglio disabilitare solo le chiamate e gli sms è possibile ????? ho disabilitato GPRS. C'è qualche metodo è disponibile ???? – 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 questo richiede il permesso android.permission.WRITE_SETTINGS, e per il bluetooth android.permission.BLUETOOTH_ADMIN. Per NFC potresti aver bisogno di android.permission.NFC.

modifiche: fortemente modificati dal originale, dal momento che mi è stato effettivamente usando questo in un modo diverso nella mia app

+0

Anche il mio telefono ha wimax in Settings.System.AIRPLANE_MODE_RADIOS: "cell, bluetooth, wifi, nfc, wimax". Questo è sorprendente perché questo telefono non supporta 4G WiMax! – pmont

Problemi correlati