当我尝试在三星 Galaxy s3 上获取我的位置时,我的应用程序崩溃了。它在我测试过的其他 3 部手机上完美运行。我在三星 Galaxy s3 上只有远程测试人员,所以我无法收到错误消息。这是我的代码:
Location finalLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
locationManager.removeUpdates(locationListenerGps);
locationManager.removeUpdates(locationListenerNetwork);
Location net_loc=null, gps_loc=null;
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
gps_loc=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
net_loc=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
//if there are both values use the latest one
if(gps_loc!=null && net_loc!=null){
if(gps_loc.getTime()>net_loc.getTime())
finalLocation = gps_loc;
else
finalLocation = net_loc;
}
if(gps_loc!=null){
finalLocation = gps_loc;
}
if(net_loc!=null){
finalLocation = net_loc;
}