1

I'm encountering an issue with retrieving a WifiInfo object from an Intent on Android 13. I have an onReceive() function that is invoked by android.net.wifi.STATE_CHANGE.

The following code returns null on Android 13:

val wifiInfo: WifiInfo? = intent?.getParcelableExtra("wifiInfo", WifiInfo::class.java)

In the same project, I used the below code and it works as expected on Android 8.1.

val wifiInfo: WifiInfo? = intent?.getParcelableExtra<WifiInfo>("wifiInfo")

Has anyone encountered a similar issue or have any insights on why this might be happening on Android 13?

Thanks in advance for your help!

4
  • Where is intent coming from? Commented Jul 31, 2024 at 12:47
  • Hi, @CommonsWare. I have an onReceive(context: Context?, intent: Intent?) function that is invoked by android.net.wifi.STATE_CHANGE. Commented Jul 31, 2024 at 13:05
  • This extra was deprecated in API 28 (Android 9) and is no longer used. You should get null on all devices running Android 9 and higher. Commented Aug 12, 2024 at 12:51
  • Try using the key networkInfo instead of wifiInfo when you try to read the "extra". From the documentation it looks like this broadcast Intent should contain an "extra" with that key (it is of type NetworkInfo, not WifiInfo. Otherwise, add some logging and see what "extras" are contained in the broadcast Intent. Commented Aug 12, 2024 at 12:58

1 Answer 1

0

From the documentation:

Beginning with Android 9 (API level 28), The NETWORK_STATE_CHANGED_ACTION broadcast doesn't receive information about the user's location or personally identifiable data.

In addition, if your app is installed on a device running Android 9 or higher, system broadcasts from Wi-Fi don't contain SSIDs, BSSIDs, connection information, or scan results. To get this information, call getConnectionInfo() instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.