任何人都可以告诉我如何通过Android中的单击按钮以编程方式将手机置于飞行模式中吗?
答案 0 :(得分:2)
请参阅博客文章http://dustinbreese.blogspot.in/2009/04/andoid-controlling-airplane-mode.html,
仅适用于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是否启用飞行模式。
答案 1 :(得分:1)
尝试将手机置于飞行模式。
// read the airplane mode setting
boolean isEnabled = Settings.System.getInt(
getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
// toggle airplane mode
Settings.System.putInt(
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权限
答案 2 :(得分:-1)
this code to make phone silent
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
还有振动模式和正常模式
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);