前言
使用app给手机设置代理,查询代理功能,但是要root的。
关键代码
原理就是通过adb命令设置代理,然后我打包成了一个app。
1 2 3 4 5
| private void setProxy() { String proxyStr = edit.getText().toString().trim(); RootCmd.execRootCmdSilent("settings put global http_proxy "+proxyStr); Toast.makeText(this, "设置成功", Toast.LENGTH_SHORT).show(); }
|
查询代理。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| private void refresh() { StringBuilder sb=new StringBuilder(); Properties properties = System.getProperties(); for (Map.Entry<Object, Object> property : properties.entrySet()) { Log.d(TAG, property.getKey() + "=" + property.getValue()); sb.append(property.getKey() + "=" + property.getValue()+"\n"); }
// 仅读取代理host和post String x=System.getProperty("http.proxyHost"); // https.proxyHost String y=System.getProperty("http.proxyPort"); // https.proxyPort Log.e(TAG,x); Log.e(TAG,y); sb.append("http.proxyHost" + "=" + System.getProperty("http.proxyHost")+"\n"); sb.append("http.proxyPort" + "=" + System.getProperty("http.proxyPort")+"\n"); text.setText(sb.toString()); }
|
CODE
android_test_proxy
APK
testproxy.apk
LINKS
Android 设置网络代理
android代码执行adb shell终端命令(linux命令)并返回执行结果
Author:
tea9
Permalink:
http://tea9.github.io/post/449313118.html
License:
Copyright (c) 2017-2025 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY?