android - BroadcastReceiver is not working (detect if wifi is connected) -



android - BroadcastReceiver is not working (detect if wifi is connected) -

i'm trying utilize broadcastreceiver observe if wifi connected , display toast when status changes (wifi disonnect/reconnect/turn off) doesn't seem working. ideas?

connectionchangereceiver class:

public class connectionchangereceiver extends broadcastreceiver { @override public void onreceive( context context, intent intent ) { connectivitymanager connmgr = (connectivitymanager)context.getsystemservice(context.connectivity_service); networkinfo networkinfo = connmgr.getnetworkinfo(connectivitymanager.type_wifi); final boolean iswificonn = networkinfo.isconnected(); log.d("debug", "wifi connected: " + iswificonn); toast toast = toast.maketext(context, "wifi connected: " + iswificonn, toast.length_long); toast.show(); } }

manifest:

<uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" /> <receiver android:name="connectionchangereceiver" android:label="networkconnection"> <intent-filter> <action android:name="android.net.wifi.wifi_state_changed"/> <action android:name="android.net.wifi.state_change"/> </intent-filter> </receiver>

i go in app, , disconnect wifi, reconnect, no toast. disable wifi, no toast. re-enable it, no toast. suspect there's wrong broadcast receiver.

thanks in advance.

i got working.

my problem in manifest. putting receiver block outside application tag. 1 time moved inside, worked perfectly.

android

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -