回答
查看博客文章Android: Controlling Airplane Mode,
只能高达API 16
// 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);
其中isEnabled
是飞行模式是否启用。
我无法部署它。此代码是否在Broadcastreceiver类 – 2010-07-14 21:18:48
中发布?无论您需要执行此操作,它都可以使用。不过请记住,您需要WRITE_SETTINGS权限来执行此操作。 – Jess 2010-07-15 05:08:28
我仍然收到像Settings.System错误\t解决 – 2010-07-15 21:01:12
public static boolean getAirplaneMode(Context context) {
try {
int airplaneModeSetting = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON);
return airplaneModeSetting==1?true:false;
} catch (SettingNotFoundException e) {
return false;
}
}
请记住,从Android 4.2及更高版本开始,这已不再可能。
http://developer.android.com/reference/android/provider/Settings.Global.html#AIRPLANE_MODE_ON
- 1. 如何在autoStart设置为true后将ViewFlipper addView或removeView设置为true
- 2. 在osCommerce中将所有单选按钮设置为true或false,或者仅将true设置为true?
- 3. 如何将Type.IsGenericTypeDefinition设置为true?
- 4. StAX - 如何将XMLInputFactory.IS_VALIDATING设置为true?
- 5. 如何设置OnClientClick为true?
- 6. 如何将python变量设置为true或false?
- 7. 如何将Deflult BootstrapToggle设置为ON
- 8. 如何将IDENTITY_INSERT设置为ON?
- 9. Cookies将secureflag设置为true
- 10. enumerateChildNodesUsingBlock(),将stop设置为true
- 11. 表单提交复选框将值设置为“on”而非“true”
- 12. 如何将IsHitTestVisible设置为True将其设置为false的某个子项上?
- 13. 如何将bool true或false转换为字符串“True”或“False”
- 14. 如何在配置中将布尔值设置为true?
- 15. 被设置为true
- 16. 设置-XdisableCastChecking为true
- 17. 如何设置jquery组合框为true
- 18. 如何设置“支持统计”为True
- 19. 如何将setZOrderOnTop设置为true的GLSurfaceView顶部的片段设置为
- 20. 如何在将textIsSelectable设置为true后将EditText重置为可编辑状态?
- 21. IsHandledCreated设置为false,但在运行时将其设置为true?
- 22. 如何将UITableviewcell或UITableview设置为空?
- 23. 无法将Userform.KeyPreview设置为true
- 24. myVar = false将myVar设置为true?
- 25. WP7 - 将ListBoxItem.IsSelected设置为true从c#
- 26. jqgrid reloadGrid并将loadonce设置为true
- 27. DropDownList将所选项目设置为true
- 28. 基于xml节点值将数据设置为true或false
- 29. 使用jQuery将复选框的值设置为true或false
- 30. 使用函数将v-show设置为true或false
请注意,开/关切换飞行模式不再可能由于Android 4.2(果冻豆主要版本1)的。这是因为Google采用了BANDAGE解决方案来解决Android中的缺陷,而不是重新检查其安全模型。 – ChuongPham 2012-11-24 17:07:05