I want my application to check if Network Data Mode or Mobile Data is turned on, even if it is not currently active. In other words, I need to check whether the application will potentially depend on mobile data, even if this phone is currently connected via WiFi.
From googling, I found the following code that checks if Mobile Data is βactiveβ.
ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isMobile = activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE;
The problem with this code is that if WiFi is active, Mobile data is not reported as active, even if it is turned on.
Is it possible to change the code to determine whether mobile data is enabled and, therefore, potentially active, and not as with this code, is it currently in active connection mode?
source share