我制作了TrackerGps,但在检查gps时遇到了一些问题。在设备Lollipop我的gps是工作,但当我尝试Device Jellybean我的gps不起作用时,总是得到null并且已经在设置app中设置了权限位置
public Location getLocation() {
// provider = getProviderName();
//set provider
setProvider(provider);
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// getting GPS status
boolean statusProvider = locationManager.isProviderEnabled(provider);
if (locationManager != null) {
if (statusProvider) {
//set can get location
setCanGetLocation(true);
locationManager.requestLocationUpdates(provider, ValueConfig.MIN_TIME_BW_UPDATES, ValueConfig.MIN_DISTANCE_CHANGE_FOR_UPDATES, locationListener);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(getProviderName());
if (location != null) {
setLatitude(location.getLatitude());
setLongitude(location.getLongitude());
setAccuracy(location.getAccuracy());
}
}
} else {
Shorcut.turnGPSOn(context);
}
} else {
Shorcut.turnGPSOn(context);
}
return location;
}
和我的应用程序,打开时会显示设备棒棒糖的充值检查权限
答案 0 :(得分:0)
检查设置中的应用权限。我建议您使用Google融合位置提供商来获取位置。因为它可以提供最佳和准确的结果。