Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取iso国家代码_Android - Fatal编程技术网

Android 获取iso国家代码

Android 获取iso国家代码,android,Android,如何获取iso3国家代码。当我存储服务器但它不是存储数据库的100%时?我正在使用这些代码。请帮助我,谢谢并提前 geocoder = new Geocoder(this); locationManager = (LocationManager)getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); bestProvider =locationManager.getBestProvider(criteri

如何获取iso3国家代码。当我存储服务器但它不是存储数据库的100%时?我正在使用这些代码。请帮助我,谢谢并提前

 geocoder = new Geocoder(this);
 locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider =locationManager.getBestProvider(criteria,false);
location = locationManager.getLastKnownLocation(bestProvider);
if(location!=null)
{
  lat=location.getLatitude();
  lng=location.getLongitude();
}
else
 {
location = new Location("");
location.setLatitude((double)38.0000000000);
location.setLongitude((double)-97.0000000000);
lat =location.getLatitude();
lng=location.getLongitude();
 }
Log.e("","Latitude and Longitude"+"Latitude="+lat+"Longitude="+lng);
try
{   
addresses=geocoder.getFromLocation(lat,lng, 1);
}
catch (IOException e) 
{   
  e.printStackTrace();
}
if (addresses != null && addresses.size() > 0)
{
 Address address = addresses.get(0);
 Log.e("Address=",""+address);
 locale = address.getCountryCode();
 Log.e("Locale",""+locale);
 Toast.makeText(SongsList.this,  "LocaleName"+locale,Toast.LENGTH_LONG).show();
} 

countryISO3=context.getResources().getConfiguration().locale.getISO3Country()?

您可以使用电话管理器:


这将为您获取所连接网络的国家/地区。

要从该国家/地区获取ISO代码:

TelephonyManager tm;
tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
String loc = tm.getSimCountryIso();
Toast.makeText(SongsList.this, "LocaleName" + loc, Toast.LENGTH_LONG).show();

我已经在使用此代码。事实上,我有两个移动三星galaxy ace和Htc Desire。Htc Desire工作正常(IND)和三星galaxy ace获得英国国家代码(GRB)。您有什么回答吗?请提前帮我谢谢。
locale=address.getCountryCode();语言环境loc=新语言环境(语言环境);Toast.makeText(SongsList.this,“iso3:+loc.getISO3Country(),Toast.LENGTH\u LONG.show())它不显示任何值。当我使用Locale loc=newlocale(Locale);我要指出的是,这会为您提供SIM卡的国家/地区,在漫游的情况下,这可能与用户实际所在的国家/地区不同。此外,设备中可能没有SIM卡。