简体   繁体   English

使用PendingIntent切换飞行模式

[英]Using a PendingIntent to toggle airplane mode

I am working on an app for Android, for which I would like to be able to toggle Airplane Mode using a PendingIntent. 我正在开发适用于Android的应用程序,我希望能够使用PendingIntent切换飞行模式。 Is this possible? 这可能吗? If so, how would I do it? 如果是这样,我该怎么办? Any help would be greatly appreciated! 任何帮助将不胜感激!

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM