Вопрос

I had tried using TelephonyManager

TelephonyManager telephonyManager=(TelephonyManager)getBaseContext().
    getSystemService(Context.TELEPHONY_SERVICE);
String CountryIso= telephonyManager.getNetworkCountryIso();
String NetworkIso=telephonyManager.getSimCountryIso();
Это было полезно?

Решение

There are always huge discussions about this, and I never understand why developers and companies go for the complex way. The language selected by the user, means the language he/she wants to see always in his/her phone. They don't intend to have apps in a different language than others or the system.

The choice is very straight forward: Use Locale (to get the language the user selected as preferred), or make your best to piss them off showing them information in a language they already said they don't want to see things in.

To get the country code use:

Locale.getDefault().getCountry();

Другие советы

Without TelephonyManager, It is not straight forward to get country. Locale also has its own issues in countries like India. Many of the Samsung phones in India has en_UK as default language set and many regional languages. Unless one is using regional language (which is very less possibility in India), this locale get country won't give India as default country. Nexus has locale as English (India) which is not found in many of the Samsung phones, i tried.

So i won't recommend using this if your audience is in India (or where English is a major language compare to local language). Pls use the link given by StarsSky in this case.

//Locale.getDefault().getCountry(); - Will not work for India

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top