-1

I have simple Registration Activity, where I have Country name field. But I need to get the Country name of the user automatically and make that field Non-editable.

I can get the country name using GPS, but the user may wonder why he need Location permission.

What I tried:

I already see

How to get country name in android?

Get location name from fetched coordinates

Get country from coordinates?

Using User Locale

 String country = getApplicationContext().getResources().getConfiguration().locale.getDisplayCountry();

with this, I can get the country name based on language settings of the user. The problem with this method is, 99% of User set their language to English-US so I don't achieve what I want.

Is there any way to get Country name other than above methods.

Hope is should be a way to get Country name (example by network properties or system properties or sim services ), Is There ???

Note: My application have SMS registration process (app is free in google play store, but payment has to done by SMS), I gave full access of app to some countries for free of cost.(Its depend on county names)

Appreciate your help.

Community
  • 1
  • 1
Kathi
  • 1,061
  • 1
  • 16
  • 31
  • 2
    "I need to get the Country name of the user automatically" -- **what** country? Is it the country where the user was born? Is it the country where the user is currently living? Is it the country where the user is at the time of filling in your form (e.g., GPS)? Is it the country where the phone was purchased? Is it the country where the SIM card was purchased? Is it the country where the user holds a passport? Is it some random country? – CommonsWare Apr 16 '16 at 11:00
  • Sorry for confuse Question, Is it the country where the user is at the time of filling in my form – Kathi Apr 16 '16 at 11:02

1 Answers1

1

The only way to find out the country where the user is located at present is to find out the user's location, and from that (hopefully) derive the country. This will require ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION, along with a suitable API (e.g., LocationManager).

I say "hopefully" because:

  • Locations may not be that accurate
  • Location data may not be available
  • Country borders, in some portions of the world, are fluid
  • Geolocation databases (to translate latitude/longitude to an address) have errors

Personally, I would not use the approach that you are planning, for technical and possibly legal reasons.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491