0

Possible Duplicate:
What Country is the User Currently In?
How to programmatically detect in which country the android device is located currently without using GPS?

Is it possible to prevent an app, downloaded on the user's device, from launching based on the country of the user's device? How can I accurately determine the user's country?

My app will be available on both WiFi and Carrier (GSM/CDMA) based devices.

I know I can restrict the app to certain geographies on Google Play but there is nothing preventing users from downloading the app here in US and then travelling to their own country and using the app. So, I want to exit the app soon as I know the user is outside of US. I can think of these mechanisms of determining the location but unsure if these are fool-proof:

  1. IMEI - not helpful, I can buy the device in US but use it anywhere
  2. SIM - I can use a SIM from US and be on roaming etc
  3. WiFi - don't think I can accurately tell the user's geo
  4. Date/Time settings - I can always pretend I am in US
  5. TelephonyManager - I couldn't tell if any methods here would help in accurately determining the location

What are my options?

Thanks!

Community
  • 1
  • 1
Anil Gorthy
  • 869
  • 3
  • 13
  • 30
  • 1
    I believe that you have answered your own question. As an example, many people in the UK downloaded the "app of the day" from Amazon whilst it was US only. There is no fool proof way. – Simon Jan 31 '13 at 16:56
  • 1
    Possible duplicates: [here](http://stackoverflow.com/questions/10755534/how-to-programmatically-detect-in-which-country-the-android-device-is-located-cu) and [here](http://stackoverflow.com/questions/4044356/what-country-is-the-user-currently-in) – vault Jan 31 '13 at 16:58
  • 1
    Combine it. But the question is, why do you wanna restrict it? – Leandros Jan 31 '13 at 17:00
  • `TelephonyManager.getCellLocation()` bypasses mock locations. – 323go Jan 31 '13 at 17:10
  • 1
    @Leandros because of some legal/privacy policy, I can't have people use the app outside US. – Anil Gorthy Feb 03 '13 at 03:23

4 Answers4

0

I'd say IP geolocation if your app requires a connection.

Stéphane
  • 6,920
  • 2
  • 43
  • 53
0

If a user has access to the device, he / she can always fake the location.

You have to decide how much effort you want to spend to keep people from using your app. There is a tradeoff beween your effort and how hard it will be to use your app outside the US. You will never exclude everyone ;)

Thus, I suggest to implement a few easy mechanisms.

Dan
  • 1,539
  • 12
  • 23
0

First, get the LocationManager. Then, call LocationManager.getLastKnown Then, create a GeoCoder and call GeoCoder.getFromLocation . Do this is a separate thread!! This will give you a list of Address objects. Call Address.getCountryName and you got it.

this might be useful

Ashish Jani
  • 295
  • 3
  • 14
0

You could get the location by GPS at startup of your app. You could check for the country, if it's not the US the user can't open the app. I think you should take a look at this: http://developer.android.com/reference/android/location/Address.html

Raymond P
  • 752
  • 2
  • 15
  • 27