Category Archives: Network

Check if Connected to Internet & if isConnected to Wifi in Android.

This sample code checks whether the android device is connected to Internet and
if it is connected to internet, it is connected to Wifi or Not?

package com.coderzheaven.demo1;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;

public class MainActivity extends Activity {

	NetworkInfo activeNetwork;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (connectedToInternet())
			System.out.println("Connected to Internet.");
		else
			System.out.println("Not Connected to internet");

		if (isWifi())
			System.out.println("Connected to Wifi.");
		else
			System.out.println("Not Connected to Wifi");
	}

	Boolean connectedToInternet() {
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

		activeNetwork = cm.getActiveNetworkInfo();
		return (activeNetwork != null && activeNetwork
				.isConnectedOrConnecting());

	}

	Boolean isWifi() {
		return (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI);
	}
}

MAKE SURE YOU ADD BELOW PERMISSION TO THE ANDROID MANIFEST

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

How to find your Google Plus ID

This is so simple

1. Go to your Google + account (https://plus.google.com/).

2. Click on the Profile icon on the Left.

3. If you look at the URL in the address bar, it should look something like this:

https://plus.google.com/104653270154306099169/posts

4. The long numerical string in the URL is your Google+ ID. Here is CoderzHeaven’s from the URL above:

104653270154306099169/

Google + CoderzHeaven