Created
January 17, 2013 17:24
-
-
Save slashthinking/4557706 to your computer and use it in GitHub Desktop.
http://www.linuxidc.com/Linux/2011-10/46151.htm 检测android网络问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (connectivity != null) { | |
// 获取网络连接管理的对象 | |
NetworkInfo info = connectivity.getActiveNetworkInfo(); | |
if (info != null && info.isConnected()) { | |
// 判断当前网络是否已经连接 | |
if (info.getState() == NetworkInfo.State.CONNECTED) { | |
if(info.getTypeName().equals("WIFI")){ | |
else{ | |
Uri uri = Uri.parse("content://telephony/carriers/preferapn"); | |
Cursor cr = context.getContentResolver().query(uri, null,null, null, null); | |
while (cr != null && cr.moveToNext()) { | |
// APN id | |
@SuppressWarnings("unused") | |
String id = cr.getString(cr.getColumnIndex("_id")); | |
// APN name | |
@SuppressWarnings("unused") | |
String apn = cr.getString(cr.getColumnIndex("apn")); | |
// do other things... | |
String strProxy = cr.getString(cr.getColumnIndex("proxy")); | |
String strPort = cr.getString(cr.getColumnIndex("port")); | |
if(strProxy != null && !"".equals(strProxy)){ | |
Config.host = strProxy; | |
Config.port = Integer.valueOf(strPort); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment