简体   繁体   English

如何使用root在Android 4.2及更高版本上切换飞行模式?

[英]How to toggle Airplane Mode on Android 4.2 and above using root?

As is known, on Android 4.2 only system applications can toggle Airplane Mode. 众所周知,在Android 4.2上,只有系统应用程序可以切换飞行模式。 But I think it must be available for rooted devices. 但我认为它必须适用于root设备。 And I want to impliment it in my application for rooted devices with Build.VERSION.SDK_INT>=17. 我希望在我的Build.VERSION.SDK_INT> = 17的root设备应用程序中实现它。 How to toggle Airplane Mode on rooted devices with Android 4.2? 如何在Android 4.2的root设备上切换飞行模式?

There is a new "settings" binary in Android 4.2 You can also use it without su, then your app needs the permission required to change this setting declared in your app's manifest (which would be WRITE_SECURE_SETTINGS for flight mode in 4.2 - which is only granted to apps installed on system partition). Android 4.2中有一个新的“设置”二进制文件您也可以在没有su的情况下使用它,那么您的应用程序需要更改应用程序清单中声明的​​此设置所需的权限(对于4.2中的航班模式,这将是WRITE_SECURE_SETTINGS - 仅授予到系统分区上安装的应用程序)。

Activate 启用

su 
settings put global airplane_mode_on 1
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true

Deactivate 停用

su
settings put global airplane_mode_on 0
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false

For other android versions and other settings (flight mode can be activated without root before 4.2) you can use sql injects in settings.db 对于其他Android版本和其他设置(在4.2之前可以在没有root的情况下激活飞行模式),您可以在settings.db中使用sql注入

su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
insert into global values(null, 'airplane_mode_on', 1);

Replace "global" with "system" or "secure" and 'airplane_mode_on' with the key of your desired table entry. 将“global”替换为“system”或“secure”,将“airplane_mode_on”替换为所需表条目的键。 For some settings you need to send certain broadcasts afterwards, see example above for flight mode. 对于某些设置,您需要在之后发送某些广播,请参阅上面的示例了解航班模式。

To explore your settings.db run this in a terminal app: 要探索你的settings.db在终端应用程序中运行:

su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
.tables
select * from global
select * from secure
select * from system

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

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