Android应用判断是否使用VPN以及是否使用代理
其他
2018-07-08 20:02:26
阅读次数: 0
-
-
-
-
private boolean isWifiProxy(){
-
final
boolean is_ics_or_later = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
-
-
-
-
proxyAddress = System.getProperty(
"http.proxyHost");
-
String portstr = System.getProperty(
"http.proxyPort");
-
proxyPort = Integer.parseInt((portstr !=
null ? portstr :
"-1"));
-
System.out.println(proxyAddress +
"~");
-
System.out.println(
"port = " + proxyPort);
-
-
proxyAddress = android.net.Proxy.getHost(MainActivity.
this);
-
proxyPort = android.net.Proxy.getPort(MainActivity.
this);
-
Log.e(
"address = ", proxyAddress +
"~");
-
Log.e(
"port = ", proxyPort +
"~");
-
-
return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -
1);
-
-
-
-
-
-
public static boolean isVpnUsed() {
-
-
Enumeration niList = NetworkInterface.getNetworkInterfaces();
-
-
for (NetworkInterface intf : Collections.list(niList)) {
-
if(!intf.isUp() || intf.getInterfaceAddresses().size() ==
0) {
-
-
-
Log.d(
"-----",
"isVpnUsed() NetworkInterface Name: " + intf.getName());
-
if (
"tun0".equals(intf.getName()) ||
"ppp0".equals(intf.getName())){
-
-
-
-
-
-
-
-
-
-
-
-
-
private boolean isWifiProxy(){
-
final
boolean is_ics_or_later = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
-
-
-
-
proxyAddress = System.getProperty(
"http.proxyHost");
-
String portstr = System.getProperty(
"http.proxyPort");
-
proxyPort = Integer.parseInt((portstr !=
null ? portstr :
"-1"));
-
System.out.println(proxyAddress +
"~");
-
System.out.println(
"port = " + proxyPort);
-
-
proxyAddress = android.net.Proxy.getHost(MainActivity.
this);
-
proxyPort = android.net.Proxy.getPort(MainActivity.
this);
-
Log.e(
"address = ", proxyAddress +
"~");
-
Log.e(
"port = ", proxyPort +
"~");
-
-
return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -
1);
-
-
-
-
-
-
public static boolean isVpnUsed() {
-
-
Enumeration niList = NetworkInterface.getNetworkInterfaces();
-
-
for (NetworkInterface intf : Collections.list(niList)) {
-
if(!intf.isUp() || intf.getInterfaceAddresses().size() ==
0) {
-
-
-
Log.d(
"-----",
"isVpnUsed() NetworkInterface Name: " + intf.getName());
-
if (
"tun0".equals(intf.getName()) ||
"ppp0".equals(intf.getName())){
-
-
-
-
-
-
-
-
-
转载自blog.csdn.net/qq_15949077/article/details/80870870