How to get user country code on Android?

How can I get the user country code on Android? Do I need permissions?

+5
source share
4 answers

To get the country code stored on your phone’s SIM card, you can try

TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getSimCountryIso();

You can also try:

 Locale locale = Locale.getDefault();
 locale.getCountry();

This returns data in the language / country specified by the user, and not in the physical location.

+12
source

Latitude and longitude of the current location

You will get latitude and longitude.

Google Map , , ( , ).

+1

: , :

context.getResources().getConfiguration().locale;

, . getCountry(), ISO, ISO 3166-1. , java- , , .

0
source

You can try the following function. It returns your ISO country code:

  TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);

        public String getSimCountryIso() {

    return telephonyManager.getSimCountryIso();

}

Add the AndroidManifest.xmlresolution below to your file .

 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
0
source

All Articles