0

im building an application that requires the country the user is in. I have no problem getting the country if the user is using a smart phone with

telephonyManager.getNetworkCountryIso()

but how can I achieve this if they are not using a sim, i.e. a nexus 7???

Any help would be greatly appreciated

Thanks

Dean Clancy
  • 517
  • 3
  • 6
  • 16
  • Nexus 7 is not a smartphone, and has no capabilities to call or send sms, so I don't think this option is available for that device. – hardartcore Jul 22 '13 at 09:20
  • i know its not a smart phone, i have one...i also know it doesnt have a sim..hence the question – Dean Clancy Jul 22 '13 at 09:58

3 Answers3

1

Try this in order to check whether the user is on a tablet or on a phone:

TelephonyManager telephonyManager1 = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

if(telephonyManager1.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
  // TABLET
}
else {
  // YOUR PREVIOUS CODE
}

Maybe you can try with the Locale, if the user is in a tablet? I know this doesn't give you the location, but maybe you can try to find out according to the Locale the user has:

String locale = context.getResources().getConfiguration().locale.getCountry(); 

Hope it helps!

noloman
  • 11,411
  • 20
  • 82
  • 129
0

You could obtain the users location (rough approximation should suffice) and then lookup the approximate address with a Geocoder to determine the country.

In fact, your question is similar to this one.

But in Android, you now get the Geocoder built-in, so no need to specially call a webservice and decode json. See the Location Guide on how to get the users location and the Geocoder API for how to retrieve the location.

Community
  • 1
  • 1
Patrick
  • 4,720
  • 4
  • 41
  • 71
0

Personally, I would extend the logic to something like this:

  • Use TelephonyManager
  • If no modem/SIM is present, use WiFi
  • If no modem/SIM is present, and WiFi is disabled, use GPS
  • If no modem/SIM is present and both WiFi and GPS are disabled, use Locale

This way you would cover as much scenarios as possible.

NB Locale will not provide you with your current country, but is dependent on what language is selected in your Android device. I.e., if your phone is in Russian, you will always get Russia.

Community
  • 1
  • 1
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95