I have a button which acts as an network state indicator just like online offline. My question is I have a WifiStatusReceiver
class which extends broadcast receiver
.
I want to enable or disable a button from WifiStatusReceiver
class. How can I do that ??
public class Wifi extends BroadcastReceiver implements ActionBar.TabListener{
ActionBar actionBar;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null
&& activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
Toast.makeText(context, "Wifi Connected!", Toast.LENGTH_SHORT).show();
actionBar.setCustomView(R.layout.header);
actionBar.getCustomView().findViewById(R.id.btn_onlinestatus).setBackground(context.getResources().getDrawable(R.drawable.onlinestaticon));
} else {
Toast.makeText(context, "Wifi Not Connected!", Toast.LENGTH_SHORT).show();
actionBar.setCustomView(R.layout.header);
actionBar.getCustomView().findViewById(R.id.btn_onlinestatus).setBackground(context.getResources().getDrawable(R.drawable.offlinestaticon));
}
}
If i try to set the background of a button its throwing a null pointer exception stating "java.lang.RuntimeException: Unable to start receiver com.balaji.example.Operations.Wifi: java.lang.NullPointerException"