2012-03-02 196 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