2011-11-21 55 views

回答

3

這應該做的伎倆。當連接槽WIFI當連接到移動 網絡或1

ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); 

if(networkInfo != null && networkInfo.isConnected()){ 
    //Your code here 
} 
0

你應該看看the documentation

isProviderEnabled(LocationManager.NETWORK_PROVIDER)是你所需要的

+0

其實,我想檢查手機是否有EDGE/GPRS/3G。 –

1
final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); 
int type = networkInfo.getType(); 
String typeName = networkInfo.getTypeName(); 
boolean connected = networkInfo.isConnected() 
  • networkInfo.getType()將返回0
  • networkInfo.getTypeName() 將返回字符串mobileWIFI
  • networkInfo.isConnected() 會告訴你你是否有活動連接。