有时候我们需要通过adb命令去修改安卓手机的代理,可以通过以下两种方案去实现。针对部分手机执行第一种方式的时候可能会提示:Can't not modify the settings in prd firmware!,如果出现这种错误提示可以使用第二种方式,目前大部分手机都可以直接用第一种方式处理。
一、使用全局命令
设置代理:
adb shell settings put global http_proxy 代理IP地址:端口号
如:
adb shell settings put global http_proxy 127.0.0.1:8888
移除代理:
adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port
注意:移除代理后要重启手机才能生效。设置代理可以多次设置,立即生效。
但是,adb shell settings delete global http_proxy,再有些没有delete参数的设备上报错?
Invalid command: delete
usage: settings [--user NUM] get namespace key
settings [--user NUM] put namespace key value
'namespace' is one of {system, secure, global}, case-insensitive
If '--user NUM' is not given, the operations are performed on the owner user.
解决方法,sqlite中找到settings.db,在数据库中删除代理信息(需要Root)
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
sqlite> select * from global;
sqlite> delete from global where name="global_http_proxy_host";
sqlite> delete from global where name="global_http_proxy_port";
sqlite> delete from global where name="http_proxy";
然后重启设备:reboot
如果不进入adb shell,执行会报错:
Error: unable to open database "/data/data/com.android.providers.settings/databases/settings.db": unable to open database file
解决办法是执行adb shell命令进入android shell界面,再执行sqlite3命令。
二、使用第三方apk
AndroidProxySetter工具可以帮助我们使用adb命令可以快速进行wifi代理的设置和清除
GitHub地址:
https://github.com/jpkrause/AndroidProxySetter
下好apk后,安装到手机
adb install proxy-setter-debug-0.2.1.apk
设置代理:
adb shell am start -n tk.elevenk.proxysetter/.MainActivity -e host 代理IP地址 -e port 端口号 -e ssid WIFI名称 -e reset-wifi true -e key WIFI密码
如:
adb shell am start -n tk.elevenk.proxysetter/.MainActivity -e host 127.0.0.1 -e port 8888 -e ssid YOUR-WIFI-NAME -e reset-wifi true -e key YOUR-WIFI-PASSWORD