Question Detail

how to get country name in android programmatically without GPS ?

5 years ago Views 11144 Visit Post Reply

I want to show Rs and Doller in my app according to the Country but I don't want to get permission to get User's Current Country.

I will change Rs. sign to Doller if User's Country is not India that will get by User's Mobile Location.

I have tried many things like 

String localeCountryCode= this.getResources().getConfiguration().locale.getCountry();

it giving me Result for not what I want 

this code gets User's Default set Location in Setting.

But I want real Location Only Country.

How to get Mobiles Current Country Name Or Country Code without any Permission and User's Interaction with android?


Thread Reply

Hemant Sharma

- 5 years ago

TelephonyManager telephoneManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = telephoneManager.getNetworkCountryIso();

 

This code will return you your Mobile's Sim Localtion and tell you where are you in country.

It will work in your Scenario.

Hemant Sharma

- 5 years ago

TelephonyManager telephoneManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = telephoneManager.getNetworkCountryIso();

 

This code will return you your Mobile's Sim Localtion and tell you where are you in country.

It will work in your Scenario.

Anonymous

- 5 years ago

You can get Default Selected Country while you setup Your Android Mobile.

String countryCodeValue="";
Locale localCountry = Locale.getDefault();
countryCodeValue=localCountry.getDisplayCountry();
Log.d("TAG", "Country: " + countryCodeValue);