6

I'm trying to detect wether the device is roaming or not in my app and I've found these two methods:

Is there an essential difference between them or can I just choose one?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Romain Piel
  • 11,017
  • 15
  • 71
  • 106

1 Answers1

4

I think TelephonyManager.isNetworkRoaming()is 2G-related, whether NetworkInfo.isRoaming() is 3G-related - setting data-roaming on/off is a distinct option in the android-settings, so if it's off you still may get truefor GSM (TelephonyManager.isNetworkRoaming())

DonGru
  • 13,532
  • 8
  • 45
  • 55
  • I'm not sure to get your answer. In my settings, I have only one check field ro allow on not Data Roaming. I've seen the field 'Use only 2G networks' but I don't really see the link with my question. – Romain Piel Aug 30 '11 at 14:38
  • Sorry my answer might be a bit confusing. If the user is data roaming, that only mean he's using a service different from the one he applied to, right? 2G or 3G wouldn't make any difference then. – Romain Piel Aug 30 '11 at 14:41
  • 1
    well, if you're outside your home country and you turn on the phone it will automatically establish a GSM connection to the roaming partner network -> `TelephonyManager.isNetworkRoaming()` will return `true`. If data roaming is disabled or 'use only 2g' is enabled `NetworkInfo.isRoaming()` will return `false`, because no data connection is established. If you switch data services on `NetworkInfo.isRoaming()` will return `true` as well, since now both (GSM and data connection) are established and in roaming mode – DonGru Aug 30 '11 at 14:43
  • 1
    Ok I see now. That makes sense. Since I have no way to test that, I'm going to wait for a couple of hours to validate that answer. If someone could confirm this explanation, that would be great. Thanks! – Romain Piel Aug 30 '11 at 14:49