2011-09-09 16 views

答えて

5

EDIT:このソリューションはまた、あなたが唯一の無線をオフにしたい場合は、私はそれがこの問題に関連と思う...など、

をブルートゥースを無線LANをオフにします:http://code.google.com/p/android/issues/detail?id=1065 私は見つけることについて本当に悲観的です良い解決策ですが、他の答えを見て好奇心。

は、ブログの記事Android: Controlling Airplane Mode

isEnabledは機内モードが有効になっているかどうかである
// 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); 

を参照してください。

これを行うには、WRITE_SETTINGS権限が必要であることを忘れないでください。

+0

+1良い解決策は、あなたが機内モードに電話を切り替えますときにもWi-Fiを提供して抑制します –

+0

自分のアプリで、元以降に変更とブルートゥース。私はそれが期待されるものだとは思わない。プライマリタスクは、GSM接続のみを抑制することでした... – barmaley

+0

yes.iは既にairplanemodeで試しました。それはブルートゥースも無効になります。しかし、私は電話とSMSを無効にしたいのですか?私はGPRSを無効にしました。任意の方法はavailbleですか? – 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 

当然、これは許可android.permission.WRITE_SETTINGS、およびBluetooth android.permission.BLUETOOTH_ADMINのためにする必要があります。 NFCの場合、android.permission.NFCが必要になる場合があります。

EDITS:私は実際には別の方法でこれを使用していたので、重く

+0

私の電話には、Settings.System.AIRPLANE_MODE_RADIOSに「wimax」というセルがあります。「cell、bluetooth、wifi、nfc、wimax」。この電話は4G WiMaxをサポートしていないので、これは驚くべきことです! – pmont

関連する問題