开发者

Android run different functions depend on country

开发者 https://www.devze.com 2023-04-06 16:41 出处:网络
I want to run different functions to my app depending of the country of the user For example if Country is US then

I want to run different functions to my app depending of the country of the user For example if Country is US then do this if country 开发者_开发百科is UK then do this

....could someone help me? Thank you in advance


You can use different approaches:

String locale = context.getResources().getConfiguration().locale.getCountry(); 

gets the country according to the phone settings (this can be changed by the user), whereas

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = tm.getSimCountryIso();

gets the country of the sim card (can not be changed by the user)

So you have the choice what fits your needs best


Use Locale.getDefault() to get the current user's Locale, and do whatever you like from the language code and country code that you get from that.

0

精彩评论

暂无评论...
验证码 换一张
取 消