2015-04-07 85 views
0

我想根據我的設備當前位置獲取國家代碼。我已經使用了LocationListener如下:Android獲取國家代碼的位置

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
locationListener = new LocationListener() { 

public void onLocationChanged(Location location) { 
    makeUseOfNewLocation(location); 
} 

locationManager.requestLocationUpdates(
     LocationManager.GPS_PROVIDER, 0, 0, locationListener); 

...但它需要很長時間才能返回位置。

如何更快地獲得國家/地區代碼?

+0

請提供到目前爲止你已經嘗試過的代碼.... – Gunaseelan

+0

的LocationManager =

您也可以使用最後已知位置獲得您的位置更快解決問題 \t \t \t \t(LocationManager)getSystemService(Context.LOCATION_SERVICE); \t \t LocationListener的新= LocationListener的(){ \t \t \t公共無效onLocationChanged(地點位置){ \t \t \t \t makeUseOfNewLocation(位置); \t \t \t} –

+0

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener); –

回答

0

而不是位置,也許你應該使用Locale

例如:
國家代碼:

Locale.getDefault().getCountry 

語言代碼:

Locale.getDefault().getLanguage() 

希望它的幫助。

+0

感謝您的回覆,但它有一些問題。像它返回設備製造商國家代碼不是目前.... –