wrk-fmd / CoCeCl

Android App for CoCeSo
3 stars 0 forks source link

ConnectionManager BroadcastReceiver NPE #2

Closed sneida closed 8 years ago

sneida commented 8 years ago

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();

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();
        }
    }
};`