shounakmulay / Telephony

Flutter plugin for telephony features like query device sms directory, listen for incoming messages, retrieve various network parameters, etc.
https://telephony.shounakmulay.dev
MIT License
139 stars 126 forks source link

Mobile Data #74

Closed tirth-stasis closed 3 years ago

tirth-stasis commented 3 years ago

I want to detect whether android device is connected to the internet via mobile data or not. connectivity plugin doesn't help here because whenever WiFi and Mobile Data both are on, it return WiFi.

I want to know whether cellularDataState (https://shounakmulay.gitbook.io/telephony/network-data-and-metrics#cellulardatastate) method fulfilling my use-case and correct way of checking/detecting this.

Thanks.

shounakmulay commented 3 years ago

Hey @tirth-stasis

The thing about this plugin is that it replicates the features that TelephonyManager provides. So you can just look up the docs for that to figure out if this is indeed what you need. https://developer.android.com/reference/android/telephony/TelephonyManager#getDataState()

But I don't think this is the correct solution in your case. It actually makes sense that it returns WiFi because your mobile data is not connected at that point. If you add a Network Callback to ConnectivityManager on android you will see that once you connect to WiFi, the onLost method is called with the connection id of you mobile data connection.

tirth-stasis commented 3 years ago

Let me check Network Callback.

But I don't think this is the correct solution in your case. It actually makes sense that it returns WiFi because your mobile data is not connected at that point.

Connectivity plugin return WiFi whenever WiFi and Mobile Data both are on.