2015-04-07 91 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

感谢您的回复,但它有一些问题。像它返回设备制造商国家代码不是目前.... –