是否有任何标准方法可以获取安卓设备的国家/地区代码?



据我所知,在Android设备中,我们可以通过获取属性ro.product.region直到版本5.X和更高版本中的ro.product.locale来获取国家/地区代码。但在某些设备(例如:联想标签4 8(中,没有ro.product.region或ro.product.locale。取而代之的是属性ro.lenovo.country,它给出了国家代码。除了读取上述 ro.product.region/locale 属性之外,是否有任何标准方法可以获取设备的国家/地区代码?我需要它在所有设备上工作,而不管制造商如何。

如果安卓手机中有sim,您可以使用下面获取国家代码。

TelephonyManager tm =  (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();

查看如何在不使用 GPS 的情况下获取我的安卓设备国家/地区代码? 以了解更多说明。

试试这个

TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String DEVICE_COUNTRY = manager.getSimCountryIso();

为我工作

最新更新