Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfo

0
public class NetworkStateReceiver extends BroadcastReceiver {
 
	public static boolean isConnectedTo3G(Context context)
	{ 
		ConnectivityManager connectivity = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = connectivity.getActiveNetworkInfo();
 
		// no connection or background data disabled 
		if(info == null || !info.isConnected())
			return false; 
	 
		return (info.getType() != ConnectivityManager.TYPE_WIFI && info.getType() != ConnectivityManager.TYPE_WIMAX);		
	} 
	 
	@Override 
	public void onReceive(Context context, Intent intent) {
		 
		// check if we are connected via 3g or wlan 
		if(intent.getExtras() != null)
		{