简体   繁体   English

如何在API23上以编程方式在Android上开启飞行模式

[英]How to turn airplanemode ON on Android programatically on API23

I'm trying to turn airplanemode on on Android but I got the following message: 我正在尝试在Android上打开planetmode,但收到以下消息:

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE java.lang.SecurityException:权限拒绝:不允许发送广播android.intent.action.AIRPLANE_MODE

From my point of view (and some researches): 从我的观点(和一些研究)来看:

(1) I'm using all necessary permission to do that: (1)我正在使用所有必要的权限来做到这一点:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

(2) The code is not wrong: (2)代码没有错:

        Settings.Global.putInt(
                context.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON, 1);
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", true);
        context.sendBroadcast(intent);

I know that the app needs to be installed as a system app, so I'm installing that under /system/app/my-app/ (I tried /system/priv-app/my-app/ too) and added all the permissions to the folder and to the apk. 我知道该应用程序需要作为系统应用程序安装,因此我将其安装在/ system / app / my-app /下(我也尝试过/ system / priv-app / my-app /)并添加了所有文件夹和apk的权限。

The last thing that I tried was the include of android:sharedUserId="android.uid.system" at the AndroidManifest.xml, but doing that the application disappears. 我尝试的最后一件事是在AndroidManifest.xml中包含android:sharedUserId =“ android.uid.system” ,但这样做的结果是该应用程序消失了。

What am I missing here, after all those attempts? 经过所有这些尝试之后,我在这里想念的是什么?

ps: The device is rooted. ps:设备已植根。

Thanks in advance 提前致谢

It seems although Airplane Mode has become a Constant value as of API Level 17 as per the Android development documentation . 根据Android开发文档 ,似乎从API级别17开始,“飞行模式”已成为常量值。

Why are you turning airplane mode on? 为什么要打开飞行模式? Is there a certain functionality you are trying to accomplish? 您要完成某些功能吗?

I would've posted this in the comments, but I don't have enough rep... tfw 我会在评论中张贴这个,但是我没有足够的代表... tfw

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

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