I want to get a user's country code without using any permissions that need to be actively requested under android M. For example, if the user were located in China I would want to get back CH. I don't want to use "dangerous" permissions for this - neither read_phone_state
to go through the TelephonyManager
, nor location in order to try to guess based on his GPS. Is there a way to do this and if so, how?
I've tried using the following code but it's prone to failure if the user sets his language settings separate from his country (e.g. user in India sets his phone to English_US):
Resources r = paramContext.getResources();
Configuration config = r.getConfiguration();
Locale currentLocale = config.locale;
Log.d("TAG", "Country: " + currentLocale.getCountry());
The only way you can determine the user's physical location programmatically requires a dangerous
permission.
If you do not want to ask the user for the permission, then ask the user for the user's location.
I've tried using the following code
That code has nothing to do with the user's physical location.