Reputation: 404
I want to create two locationListener, one for GPS Listener and one for network listener. I write below code but when i use my listeners in requestUpdate, i get error. What is my problem and how can solved this?
public static void createLocationListener(Context contextVal) {
gpsLocListener= new MyLocationListener();
if(FIND_LOC_ByY_GPS)
networkLocListener=new MyLocationListener();
}
public static class MyLocationListener implements LocationListener {
public MyLocationListener(){}
@Override
public void onLocationChanged(Location location) {
if (location != null) {
try {
removeLocationUpdate();
if (DEBUG_BASEACTIVITY)
Log.e("GPS Location Changed!", "onLocationChanged/BaseActivity");
} catch (SecurityException e) {
Log.e("PERMISSION_EXCEPTION", "PERMISSION_NOT_GRANTED");
}
get_location_by_LocationUpdate_method=true;
doLocationUpdate(location, true);
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
Error:
java.lang.RuntimeException: Unable to start receiver com.Reciever: java.lang.IllegalArgumentException: listener==null
Upvotes: 1
Views: 217
Reputation: 442
For using GPS and other location based services, you have to get access location permission.
And if you are using Android version from 6(Marshmallow), You have to ask for permission during run time.
Upvotes: 1