我是android开发人员,我正在开发Uber,Careem等应用程序。
我有一个使用谷歌地图的功能,让用户在特定的红颜知己上设置自己的标记。
这里的问题是我的应用程序只适用于沙特阿拉伯,而吉达城市则是确切的。并且我不支持任何其他国家或城市对此的期望。
我需要一个解决方案,当用户放下他的标记以显示弹出窗口或告诉他我们还不支持这个区域时。
有没有解决方案。
谢谢,
答案 0 :(得分:0)
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* @param context Context reference to get the TelephonyManager instance from
* @return country code or null
*/
public static String getUserCountry(Context context) {
try {
final TelephonyManager mTelephonyManager= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = mTelephonyManager.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
return simCountry.toLowerCase(Locale.US);
}
else if (mTelephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
String networkCountry = mTelephonyManager.getNetworkCountryIso();
if (networkCountry != null && networkCountry.length() == 2) { // network country code is available
return networkCountry.toLowerCase(Locale.US);
}
}
}
catch (Exception e) { }
return null;
}