3

I had tried using TelephonyManager

TelephonyManager telephonyManager=(TelephonyManager)getBaseContext().
    getSystemService(Context.TELEPHONY_SERVICE);
String CountryIso= telephonyManager.getNetworkCountryIso();
String NetworkIso=telephonyManager.getSimCountryIso();
Rahul Matte
  • 1,151
  • 2
  • 23
  • 54
  • possible duplicate http://stackoverflow.com/questions/5402253/getting-telephone-country-code-with-android – StarsSky Jan 04 '14 at 20:21
  • As shown in that link, if you're running into issues with TelephonyManager you might be better off getting the Locale and doing a look up of ISO to country code. – Tom Jan 04 '14 at 21:51
  • 1
    thanks @Tom...but hw can I get country calling code like +91, +1 from Locale? – Rahul Matte Jan 05 '14 at 07:11

2 Answers2

2

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();
learner
  • 3,092
  • 2
  • 21
  • 33
  • My Phone number is +91... but my phone locale is the US, your answer is not right. – FarshidABZ Apr 12 '19 at 10:12
  • +91.. is your assumption. You need to handle settings carefully to maintain accuracy. Your requirement never happen automatically since you are against to timezones. – learner Apr 18 '19 at 08:33
1

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

Sachiin Gupta
  • 378
  • 2
  • 9