Failed to get network related events

I registered with ConnectivityManager.CONNECTIVITY_ACTION BroadcastReceiver to receive network status events, but my onReceive function onReceive not called when my Wi-Fi connection is turned on or off.

As mentioned in the docs, this is a Sticky Broadcast Receiver that starts when we register for it.

But I do not receive any events in my onReceive function when I register this receiver, what could be the reason?

In my manifest file, I have all permissions to access Internet / Network / Wifi connections and their states.

I register with this intention using the following code:

 registerReceiver(mNetworkStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); 

In my Logcat, I get the following error message register for this broadcast receiver:

 01-01 00:05:29.804: ERROR/WifiHW(1305): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": Connection refused 

What could be the reason? Is there a way to find out if BroadcastReceiver is registered correctly or not?

Thanks.

+6
source share
4 answers

This works for me:

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <receiver android:name=".receiver.ConnectivityReceiver"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> 

the code:

 public class ConnectivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d(ConnectivityReceiver.class.getSimpleName(), "action: " + intent.getAction()); } } 

and do not forget to register all network permissions.

+4
source

try using the manifest file

 <receiver android:name=".MyNetworkStateReceiver" > <intent-filter > <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> 

class MyNetworkStateReceiver should extend BroadcastReceiver

+3
source

Looks like a lower level problem. As a result of the error, Google found numerous hacked hacking forums and violations of their Wi-Fi. What are you testing? Try testing another device or emulator. (I assume you tried to reboot yours :))

Also, make sure you unregister the recipient when your activity / service was destroyed (this may be due to a connection error)

PS I know what you said you were doing, but still check what you have

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

in your manifest.

0
source

You can also try to get permissions to block the Internet, WIFI and Multicast, try adding them to the permissions.

 <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/> 

I need to use these permissions for the embedded application that I created, which uses not only WiFi to send and receive network data, but also any type of network adapter (LAN, RADIO) that I can filter through the SDK in C (The device must be rooted ) But using these permissions, I have no problem.

0
source

Source: https://habr.com/ru/post/905912/


All Articles