I have a location manager in my Android app that sometimes works. Sometimes I'll run the app and it will get location updates (with some errors). Sometimes I'll run it and it will just throw this error every couple seconds without receiving any location updates:
E/IzatSvc_PassiveLocListener: Exiting with error onLocationChanged line 152 "1"
Here is my class for managing location events:
package com.company.AppName;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
public class LocationListenerService extends JobService {
private static final String TAG = "LocationListenerService";
private LocationManager locationManager = null;
private LocationListener locationListener = null;
private String locationProvider = null;
public LocationListenerService() {}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public boolean onStartJob(JobParameters params) {
Log.i(TAG, "onStartJob");
startLocationManager(params);
return true;
}
@Override
public boolean onStopJob(JobParameters params) {
Log.i(TAG, "onStopJob");
return false;
}
public void startLocationManager(JobParameters params) {
if(locationManager != null) return;
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
locationProvider = locationManager.getBestProvider(criteria, true);
locationListener = new LocationListener();
if (locationProvider != null) {
Log.v(TAG, "Location provider: " + locationProvider);
} else {
Log.e(TAG, "Location provider is null. Location events will not work.");
return;
}
if (locationListener == null) {
Log.e(TAG, "Location listener is null. Location events will not work.");
return;
}
// Finish job after first time updating location with the server
NativeApp.shared().getLocationData((NativeApp app, String response) -> {
Log.i(TAG, "Received location data response. Finishing job.");
jobFinished(params, true);
});
try {
locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);
} catch (java.lang.SecurityException ex) {
Log.e(TAG, "fail to request location update, ignore", ex);
} catch (IllegalArgumentException ex) {
Log.e(TAG, "network provider does not exist, " + ex.getMessage());
}
}
private class LocationListener implements android.location.LocationListener {
@Override
public void onLocationChanged(Location location) {
if(location == null) {
Log.w(TAG, "onLocationChanged skipped: null location");
return;
}
Log.i(TAG, "onLocationChanged: " + location.toString());
NativeApp.shared().updateLocation(location);
}
@Override
public void onProviderDisabled(String provider) {
Log.i(TAG, "onProviderDisabled: " + provider);
}
@Override
public void onProviderEnabled(String provider) {
Log.i(TAG, "onProviderEnabled: " + provider);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.i(TAG, "onStatusChanged: " + provider);
}
}
}
Why is this happening? Why do location updates work sometimes but not other times?
EDIT: After giving up for a few hours and rerunning, the app is still throwing the error repeatedly, but after about 10 seconds logs this and starts receiving location updates:
E/XTCC-6.1.2.10: [FDAL_OSListener] handleLocationUpdate: failed: 2
D/LocationManagerService: incoming location: gps
I/LgeGnssLocationProvider: Intent - android.location.GPS_FIX_CHANGE
D/LgeGnssLocationProvider: GPS_FIX_CHANGE_ACTION! , mGpsNavigating =true
D/LocationManagerService: incoming location: gps
from Android location manager error 'Exiting with error onLocationChanged line 152 "1"'
No comments:
Post a Comment