0

How to fetch user country code in android programmatically? I have to show payment in Indian rupees for Indians and in dollars for foreigners but I am not to fetch the user current country. If I use Locale, in some of the mobiles even though they are Indians it is returning US. Please suggest ways using Android.

Method 1: Using the telephone manager

TelephonyManager tm = (TelephonyManager)getActivity().getSystemService(getActivity().TELEPHONY_SERVICE);
    String countryCodeValue = tm.getNetworkCountryIso(); 

But it won't work if there is no sim card in mobile.

Method 2:

 Locale.getDefault().

It is returning wrong.

ॐ Rakesh Kumar
  • 1,318
  • 1
  • 14
  • 24
Sirisha Ch
  • 21
  • 4
  • https://stackoverflow.com/questions/11293642/how-can-i-get-my-android-device-country-code-without-using-gps Check above links. – sagar patel Oct 04 '18 at 05:34
  • https://github.com/hbb20/CountryCodePickerProject – Gowthaman M Oct 04 '18 at 05:37
  • @sagar patel I have tried the same method from the link , but it is not working if there is no simcard in the testing mobile. – Sirisha Ch Oct 05 '18 at 08:54
  • @Gowtham M Please understand the question what I have asked. I want to fetch country code from device . I don't want user to select manually. – Sirisha Ch Oct 05 '18 at 08:56
  • @SirishaCh ya no need to select country code by default it will set your country code and it will return your country code....one more thing if sim is not present in your mobile cannot get the country code – Gowthaman M Oct 05 '18 at 09:07

0 Answers0