简体   繁体   English

Android 4.3中的飞行模式切换

[英]Airplane mode toggle in Android 4.3

I'm facing a problem in android version 4.3 to control airplane mode by code.For this I converted the user app into system using system/ app mover application available in google play.Once the user enables the airplane mode, the background service have the control to check the airplane mode and reset it to off state and send the broadcast changes to the device.Below the snippet I implemented in my code to keep the airplane mode state in off.But it fails in android version 4.3. 我在android 4.3中遇到一个问题,无法通过代码控制飞行模式。为此,我使用google play中可用的system / app mover应用程序将用户应用程序转换为系统。一旦用户启用飞行器模式,后台服务就会控件以检查飞行模式并将其重置为关闭状态,并将广播更改发送到设备。在代码段下方,我在我的代码中实现了将飞行模式状态保持为关闭状态。但是在Android 4.3版中失败。 It throws an exception called "permission denied". 它引发了一个异常,称为“权限被拒绝”。 Let me know is these any additional permission need to added in manifest or else let me know your suggestions on these issue to fixed. 让我知道是需要在清单中添加这些任何其他权限,还是让我知道您对这些问题的建议已得到解决。

try {
                    Settings.Global.putInt(context.getContentResolver(),
                            "airplane_mode_on", 0);
                    isAirplaneModeOn = isAirplaneModeOn(context);
                    Intent localIntent2 = new Intent(
                            "android.intent.action.AIRPLANE_MODE");
                    localIntent2.putExtra("state", isAirplaneModeOn);
                    context.sendBroadcast(localIntent2);
                } catch (Exception e) {
                    Log.v("TAG",
                            e.toString() + "\n" + e.getMessage());
                }

Moving an App into the /system/app folder does not turn it into a System App - it simply makes the App uninstallable because /system is normally mounted read-only. 移动应用程式到/系统/应用程序文件夹把它变成一个系统应用程序-它只是使应用程序卸载的,因为/通常安装只读的系统。

What you are trying to do requires full System App privileges. 您要尝试执行的操作需要完整的System App特权。 You can only get these by signing your app with the same key used to sign the original firmware Apps - the platform key. 您只能通过使用用于签名原始固件应用程序的相同密钥(平台密钥)对您的应用程序进行签名来获取这些密钥。 In other words, you need access to whoever built the version of Android you are running on and get them to sign your APK. 换句话说,无论是谁构建了正在运行的Android版本,您都需要访问权限,并请他们签名APK。

Actually you cannot do it starting from Android 4.2. 实际上,您无法从Android 4.2开始执行此操作。 Because that settings was relocated here from either Settings.System or Settings.Secure. 因为该设置已从Settings.System或Settings.Secure移到此处。 But on previous vesions it works fine. 但是在以前的版本上它可以正常工作。

http://developer.android.com/about/versions/android-4.2.html http://developer.android.com/about/versions/android-4.2.html

If your app is currently making changes to settings previously defined in Settings.System (such as AIRPLANE_MODE_ON), then you should expect that doing so will no longer work on a device running Android 4.2 or higher if those settings were moved to Settings.Global. 如果您的应用当前正在更改以前在Settings.System中定义的设置(例如AIRPLANE_MODE_ON),那么如果将这些设置移至Settings.Global,则应该希望这样做不再对运行Android 4.2或更高版本的设备起作用。

Related question on StackOverflow 有关StackOverflow的相关问题

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

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