我正在开发Android应用程序,我希望能够使用PendingIntent切换飞行模式。这可能吗?如果是这样,我该怎么做?任何帮助将不胜感激!
答案 0 :(得分:0)
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
boolean isEnabled = Settings.System.putInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i,PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pi);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime() + 20000, 20000, pi);