2012-03-02 192 views
-2

如何获得iso3国家code.when我存储服务器,但它不存储100%的数据库?我使用这些code.Please帮我感谢,并提前...获取ISO国家代码

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(); 
} 

回答

1

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

+0

我已经使用这个code.Actually,我有两个手机三星GALAXY ACE和HTC Desire.HTC欲望正常工作(IND)和三星Galaxy ACE获得国家代码英国(GRB)。 – 2012-03-02 07:12:58

+0

有什么答案吗? – 2012-03-02 07:21:43

+0

请帮我先谢谢.. – 2012-03-02 07:23:35

0

从国家获得ISO代码:

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

我应该指出,这给你的SIM卡的国家,这可能是不同于实际用户的国家,在漫游的情况下。此外,设备中可能没有SIM卡。 – njzk2 2012-03-02 13:46:37