public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null) {
// connected to the internet
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
// connected to wifi
//tis.setwifigreen();
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// connected to the mobile network
//tis.setmobilegreen();
}
} else {
// not connected to the internet
//tis.setred();
}
}
};`
Icons in toolbar layout should show connection state. WIFI, MOBILE, GPS, Connection to SERVER
classes: ConnectionManager.class, ToolBarIconStates.class, MainActivity(register BroadcastReceiver)
error in passing context?
`ToolbarIconStates tis = new ToolbarIconStates();