Code example for NetworkInfo

Methods: getTypeisConnectedtoString

0
			xmppServiceIntent.setAction("de.hdmstuttgart.yaxim.XMPPSERVICE");
			context.stopService(xmppServiceIntent);
		} else if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
			ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
			Log.d(TAG, "ACTIVE NetworkInfo: "+(networkInfo != null ? networkInfo.toString() : "NONE"));
			if (((networkInfo == null) && (networkType != -1)) || ((networkInfo != null) && (networkInfo.isConnected() == false) && (networkInfo.getType() == networkType))) {
				Log.d(TAG, "we got disconnected");
				networkType = -1;
				Intent xmppServiceIntent = new Intent(context, XMPPService.class);
				xmppServiceIntent.setAction("de.hdmstuttgart.yaxim.XMPPSERVICE");
				xmppServiceIntent.putExtra("disconnect", true);
				context.startService(xmppServiceIntent);
			} 
			if ((networkInfo != null) && (networkInfo.isConnected() == true) && (networkInfo.getType() != networkType)) {
				Log.d(TAG, "we got connected");
				networkType = networkInfo.getType();
				Intent xmppServiceIntent = new Intent(context, XMPPService.class);
				xmppServiceIntent.setAction("de.hdmstuttgart.yaxim.XMPPSERVICE");
				xmppServiceIntent.putExtra("reconnect", true);
				context.startService(xmppServiceIntent);
			} else 
			if ((networkInfo != null) && (networkInfo.isConnected() == true) && (networkInfo.getType() == networkType)) {
				Log.d(TAG, "we stay connected, sending a ping");
				Intent xmppServiceIntent = new Intent(context, XMPPService.class);
				xmppServiceIntent.setAction("de.hdmstuttgart.yaxim.XMPPSERVICE");
				xmppServiceIntent.putExtra("ping", true);
				context.startService(xmppServiceIntent);