Skip to content

Accessing native plugin from TaskHandler #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
insidewhy opened this issue Dec 15, 2021 · 2 comments
Closed

Accessing native plugin from TaskHandler #35

insidewhy opened this issue Dec 15, 2021 · 2 comments

Comments

@insidewhy
Copy link
Contributor

insidewhy commented Dec 15, 2021

Hi,

I want to access the Wi-Fi SSID, BSSID and RSSI from my TaskHandler so I can measure how the wifi strength varies over time. In the onEvent method of my TaskHandler I'm calling WifiInfoAndroid.getWifiInfo which is from the wifi_info_android plugin. The code for that is pretty simple, it can be found here: https://github.com/sol-x/wifi_info_android/blob/main/android/src/main/kotlin/co/solx/wifi_info_android/WifiInfoAndroidPlugin.kt

When trying to access the wifi info from the TaskHandler I always get a null value though. I'm not sure if there is a general issue with calling native code via a MethodChannel from a TaskHandler or if it's something specific to do with activity aware plugins.

Maybe I should be accessing the wifi info from receivePort.listen and only using the sendPort in the TaskHandler to indicate that the main thread should be accessing the wifi info?

@Dev-hwang
Copy link
Owner

When your app is in the background, it doesn't have an Activity object. The plugin you introduced is implemented so that null is always returned if there is no Activity object. - Line45

Try implementing it using flutterPluginBinding.applicationContext in onAttachedToEngine function instead of binding.activity.

@insidewhy
Copy link
Contributor Author

@Dev-hwang Thanks for the quick response, you really helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants