1
好吧,這是一個很奇怪的問題,但我可能錯過了一些很明顯的東西。我使用這個功能當前訪問用戶位置:訪問位置服務時,Android應用程序缺失狀態欄圖標
public String[] getGeoCoords() {
String[] geoCoords = new String[2];
String mprovider = locationManager.getBestProvider(criteria, false);
if (mprovider != null && !mprovider.equals("")) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return geoCoords;
}
Location loc = locationManager.getLastKnownLocation(mprovider);
if(loc== null)
loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (loc == null)
loc = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (loc == null)
loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
geoCoords[0] = String.valueOf(loc.getLatitude());
geoCoords[1] = String.valueOf(loc.getLongitude());
}
return geoCoords;
}
這將返回預期的位置,但訪問用戶位置時,不會出現在狀態欄上,你通常得到的圖標。
在我的清單我有
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
任何想法?
嘗試添加此權限<使用權限android:name =「android.permission.ACCESS_NETWORK_STATE」/> –