[英]Toggling Airplane mode on Android 6.0
I'm currently trying to toggle the Airplane mode programmatically using Android version 6.0. 我目前正在尝试使用Android 6.0版以编程方式切换飞行模式。
I've done quite a lot research and some people say it's not possible anymore since Version 4.2, while others say there still are some workarounds, which I've tried but didn't work for me. 我已经做了很多研究,有人说从4.2版开始就不可能了,而另一些人说仍然有一些变通办法,我已经尝试过了,但对我却不起作用。
What I've tried last is the following: 我最后尝试的是以下内容:
public static boolean isAirplaneModeOn(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} else {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}
public static void setSettings(Context context, int value) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Settings.System.putInt(
context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, value);
} else {
Settings.Global.putInt(
context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, value);
}
}
But here I get the error Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
I know that I can change these settings on the emulator, but is it also possible to change these settings on my external device? 但是在这里我得到了错误“
Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
我知道我可以在模拟器上更改这些设置,但是也可以在外部设备上更改这些设置吗? In another thread some people said that for some devices it is possible, but I couldn't figure out any specific information about my Device (HUAWEI P8 Light). 在另一个话题中,有人说对于某些设备是可行的,但我无法弄清楚有关我的设备(HUAWEI P8 Light)的任何特定信息。 So my question is, is it possible to do so, or is there even a better way to do it?
所以我的问题是,有可能这样做,还是有更好的方法呢? I've also read some about using ADB to toggle airplane mode, but there they said that this would need the same permissions.
我也阅读了一些有关使用ADB切换飞行模式的信息,但是他们说这将需要相同的权限。 I hope somebody can help me out.
我希望有人能帮助我。 :)
:)
this is not available for non system applications anymore , because Google denied this on API level. 此功能已不再适用于非系统应用程序,因为Google在API级别上对此予以拒绝。 It's possible for data connection to be enabled/disabled on rooted phones tho
可以在有根电话上启用/禁用数据连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.