My app need a function to check user's mobile phone has turned on the mobile data or not.
I have referenced this link: #32239785
Here is the code provided in that topic
boolean mobileYN = false;
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) {
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1)
{
mobileYN = Settings.Global.getInt(context.getContentResolver(), "mobile_data", 1) == 1;
}
else{
mobileYN = Settings.Secure.getInt(context.getContentResolver(), "mobile_data", 1) == 1;
}
}
This code works in most of my mobile phone.
Except on "Nokia 8"(Android 9)
Even I turned off the mobile data. This function still return true.
Why?