我正在自动执行wifi通话的测试程序,我想知道是否有办法通过adb关闭/打开wifi吗?
我想禁用/启用wifi或取消wifi通话(com.movial.wificall)并重新启动它。
是否有可能通过adb和shell命令完成所有这些操作?
到目前为止,我已经找到:
android.net.wifi.WifiManager
setWifiEnabled(true/false)
我只是不确定如何将其组合在一起
启用:
adb shell su -c 'svc wifi enable'
禁用:
adb shell su -c 'svc wifi disable'
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
adb shell input keyevent 20 & adb shell input keyevent 23
第一行启动“ wifi.WifiSettings”活动,该活动将打开“ WiFi设置”页面。第二行模拟按键。
我在Droid X上测试了这两行。但是由于不同的设置布局,上述关键事件可能需要在其他设备中进行编辑。
有关“键事件” here的更多信息。
我正在寻找相同的东西来打开/关闭蓝牙,但发现了这一点:
adb shell svc wifi enable|disable
在无根设备上切换wifi的简单方法是使用简单的应用程序:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WifiManager wfm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
try {
wfm.setWifiEnabled(Boolean.parseBoolean(getIntent().getStringExtra("wifi")));
} catch (Exception e) {
}
System.exit(0);
}
}
AndroidManifest.xml:
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
ADB命令:
$ adb shell am start -n org.mytools.config/.MainActivity -e wifi true
$ adb shell am start -n org.mytools.config/.MainActivity -e wifi false
android/android-sdk/platform-tools
在此处打开cmd并键入以下命令
adb shell
su
svc wifi enable/disable
完成!!!!!
adb shell "svc wifi enable"
此方法有效,它无需打开相关选项即可在后台执行操作!
我测试了此命令:
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23
并且仅在窗口的提示下起作用,可能是由于某些驱动程序
关于adb shell svc wifi enable|disable
,我猜只有在拥有root权限的情况下才能使用
使用引号
例如:adb shell "svc wifi enable"
这将起作用:)
我可以做:
settings put global wifi_on 0
settings put global wifi_scan_always_enabled 0
有时,如果在引导过程中完成(即修复bootloop such as this),则效果不佳,您还可以首先启用飞行模式:
settings put global airplane_mode_on 1
settings put global wifi_on 0
settings put global wifi_scan_always_enabled 0
其他选择是强制使用:
while true; do settings put global wifi_on 0; done
[已在LG G5(SE)的Android 7上使用(无根目录)股票模块进行了测试。
[所有这些input keyevent
组合都是依赖于Android /硬件的,这很痛苦。
但是,我终于找到了旧的Android 4.1设备的组合:
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
adb shell "input keyevent KEYCODE_DPAD_LEFT;input keyevent KEYCODE_DPAD_RIGHT;input keyevent KEYCODE_DPAD_CENTER"