private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
boolean isWifiConnected = false;
boolean isMobileConnected = false;
ConnectivityManager connMgr = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(networkInfo != null)
isWifiConnected = networkInfo.isConnected();
networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if(networkInfo != null)
isMobileConnected = networkInfo.isConnected();
Log.d("network status", "wifi == " + isWifiConnected + " and mobile == " + isMobileConnected);
}
};
registerReceiver(mConnReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />