1

I'm working on location based app. I am using LocationUpdatesForegroundService sample code. Which is a Service to get location details

At some case location are not getting.

like.

GPS and Internet are on I'm getting location details.

but,

GPS and Internet are in offline I'm not getting location details.

case : Start app I am start to service getting location but gps off case to first prompt to please gps ON after I gps ON.

BUT not getting LOCATION mFusedLocationClient.getLastLocation method task.getResult() are null.

please resolve my issue.

Thanks

NOTE: This code working in MOTO E os version 4.4.4. but not working in LAVA a97 os version 6.0

I'm using this sample :- https://github.com/googlesamples/android-play-location/tree/master/LocationUpdatesForegroundService

Vishal
  • 124
  • 7

2 Answers2

0

You can get only details by getting LocationUpdates in textview maps won't give you updates in offline.If you are using textview for getting updates You may forgot this.

add CourseLocation Permisssion in Manifest.xml

-1

In onCreate()

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
  // Called when a new location is found by the network location provider.
  makeUseOfNewLocation(location);
}

public void onStatusChanged(String provider, int status, Bundle extras) {}

public void onProviderEnabled(String provider) {}

public void onProviderDisabled(String provider) {}
  };
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

and finally don't forget to add permission in manifest and handle the permissions in Java code too because of dynamic permissions.

That's it.

I hope it will work fine even in offline also.

Pang
  • 9,564
  • 146
  • 81
  • 122