How can I use my Broadcast receiver? Like when my app starts how do I make the receiver continually run its code?
My Reciver code:
private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager mConnectivity;
mConnectivity = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = mConnectivity.getActiveNetworkInfo();
if (info == null || !mConnectivity.getBackgroundDataSetting()) {
wifi.setChecked(false);
return;
} else {
int netType = info.getType();
//int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
wifi.setChecked(true);
} else {
wifi.setChecked(false);
}
}
}
};
Wifi is a toggle button by the way.
Please help thanks!
You need to set an intent filter associated with your receiver in your manifest.xml file like this :
then, in you activities, when you want to call your receiver, you just
And then you should update your app, but within the ui thread to change a widget :
But I guess you receiver is an inner class inside an acitivity (only way to get a reference on a widget). So, instead of registering your receiver through xml, you should register it through code.
Have a look at this thread.
Regards, Stéphane