在 Android 中通过 Settings.Global 撤消设置代理
Undo setting proxy via Settings.Global in Android
我正在编写系统应用程序,它通过
设置全局http代理
Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, "127.0.0.1");
我怎样才能恢复这个改变?
这不起作用:
Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, null);
有什么想法吗?
提前致谢
这样使用
Settings.Secure.putString(getContentResolver(),
Settings.Secure.HTTP_PROXY, "127.0.0.1:8007");
备注'Settings.Secure.putString()'
我知道这是一个老问题,但我花了很多时间来撤消我的代理黑客攻击,所以我想分享一下。
我使用 ADB 将权限传递给设备,这样我就可以使用自己的自定义应用程序更改代理设置的值。
问题是一旦我将我的应用程序与
一起使用
Settings.Secure.putString(getContentResolver(), Settings.Secure.HTTP_PROXY, "127.0.0.1:8007");
无论我尝试什么(空,空白,"NONE"),它都不会让我将其设置回默认值(无代理),基本上如果我没有通过代理连接,它就不会与外界交谈。即使重启后。
我找到的解决方案:
这些设置存储在 SQL 数据库中,因此当 phone 重新启动时会应用它们。您只需要进入数据库并从 table 中删除这些行。我做了什么:
~user$ adb shell
shell@cinco:/ $ su -
仅供参考...不确定您是否需要超级用户,但不会有什么坏处。 . .
root@cinco:/ $ sqlite3 /data/data/com.android.providers.settings/databases/settings.db
您可以通过以下操作查看全局 table 中内容的完整列表:
sqlite> select * from global;
在列表中你应该可以看到你为http_proxy、global_http_proxy_host和global_http_proxy_port写的值,也许你知道什么是魔法值将这些设置为使其正常工作,但我没有...我的解决方案,只需删除它们:
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";
重新启动 phone 就像变魔术一样,不再有代理,我得到了互联网!!
Andrews 的答案有效,但仅适用于 root 设备,这是我针对非 root 设备的解决方案。
我使用以下命令添加了代理:
adb shell settings put global http_proxy <ip>:<port>
更新:要删除它,您可以使用以下命令(感谢 Rohit Patel 提供此命令):
adb shell settings put global http_proxy :0
要删除它,我使用了这些命令:
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 put global http_proxy :0
您不需要 运行 所有这三个命令。它仅适用于上面的一个命令。将立即删除所有代理设置。
另一种方式而不是使用 root 命令(尽管你仍然需要 root)并使用
的方法
Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, "127.0.0.1");
就是把值设为:0
所以看起来像这样
Settings.Global.putString(activity!!.contentResolver, Settings.Global.HTTP_PROXY, ":0")
我也不需要重新启动以使更改生效
我正在编写系统应用程序,它通过
设置全局http代理Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, "127.0.0.1");
我怎样才能恢复这个改变?
这不起作用:
Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, null);
有什么想法吗?
提前致谢
这样使用
Settings.Secure.putString(getContentResolver(),
Settings.Secure.HTTP_PROXY, "127.0.0.1:8007");
备注'Settings.Secure.putString()'
我知道这是一个老问题,但我花了很多时间来撤消我的代理黑客攻击,所以我想分享一下。
我使用 ADB 将权限传递给设备,这样我就可以使用自己的自定义应用程序更改代理设置的值。
问题是一旦我将我的应用程序与
一起使用Settings.Secure.putString(getContentResolver(), Settings.Secure.HTTP_PROXY, "127.0.0.1:8007");
无论我尝试什么(空,空白,"NONE"),它都不会让我将其设置回默认值(无代理),基本上如果我没有通过代理连接,它就不会与外界交谈。即使重启后。
我找到的解决方案:
这些设置存储在 SQL 数据库中,因此当 phone 重新启动时会应用它们。您只需要进入数据库并从 table 中删除这些行。我做了什么:
~user$ adb shell
shell@cinco:/ $ su -
仅供参考...不确定您是否需要超级用户,但不会有什么坏处。 . .
root@cinco:/ $ sqlite3 /data/data/com.android.providers.settings/databases/settings.db
您可以通过以下操作查看全局 table 中内容的完整列表:
sqlite> select * from global;
在列表中你应该可以看到你为http_proxy、global_http_proxy_host和global_http_proxy_port写的值,也许你知道什么是魔法值将这些设置为使其正常工作,但我没有...我的解决方案,只需删除它们:
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";
重新启动 phone 就像变魔术一样,不再有代理,我得到了互联网!!
Andrews 的答案有效,但仅适用于 root 设备,这是我针对非 root 设备的解决方案。
我使用以下命令添加了代理:
adb shell settings put global http_proxy <ip>:<port>
更新:要删除它,您可以使用以下命令(感谢 Rohit Patel 提供此命令):
adb shell settings put global http_proxy :0
要删除它,我使用了这些命令:
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 put global http_proxy :0
您不需要 运行 所有这三个命令。它仅适用于上面的一个命令。将立即删除所有代理设置。
另一种方式而不是使用 root 命令(尽管你仍然需要 root)并使用
的方法Settings.Global.putString(getContentResolver(), Settings.Global.HTTP_PROXY, "127.0.0.1");
就是把值设为:0
所以看起来像这样
Settings.Global.putString(activity!!.contentResolver, Settings.Global.HTTP_PROXY, ":0")
我也不需要重新启动以使更改生效