How can get current region's code like (i.e., us,uk) selected in Android device.
I don't want to get region/country code from locale becuase it only returns country code from language selected. Using locale :
String cCode = Locale.getDefault().getCountry();
Whenever user explicitly updates region/country, it must reflect in the app.
I need code to get current selected region/country of device
.
CodePudding user response:
I hope this will work ..
TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
CodePudding user response:
I was working on the same. This helped me:
Locale current = getResources().getConfiguration().locale;
CodePudding user response:
To get the country code, you can use the getCountry() method of the Locale class as shown in the code.
To get the full region/country name, you can use the getDisplayCountry() method of the Locale class as shown in the code above. This will return the full name of the country for the device's current locale in the language of the device.
Locale currentLocale = Locale.getDefault();
String countryCode = currentLocale.getCountry();
String regionName = currentLocale.getDisplayCountry();
For example, if the device's current locale is set to United States, the country code will be "US" and the region name will be "United States". If the device's current locale is set to France, the country code will be "FR" and the region name will be "France". So, this will return both the country name and region name.
CodePudding user response:
you can use the getNetworkCountryIso
method of the TelephonyManager
class to get the country code of the device's current network
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso();