Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created April 26, 2020 12:33
Show Gist options
  • Save Lavanyagaur22/77dc574908b9ad78e162cbb2577c0a7f to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/77dc574908b9ad78e162cbb2577c0a7f to your computer and use it in GitHub Desktop.
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
super.onLocationResult(locationResult)
if (locationResult?.lastLocation != null) {
// Get the currentLocation from the locationResult object.
currentLocation = locationResult.lastLocation
// Notify our Activity that a new location was added.
val intent = Intent(ACTION_FOREGROUND_ONLY_LOCATION_BROADCAST)
intent.putExtra(EXTRA_LOCATION, currentLocation)
LocalBroadcastManager.getInstance(applicationContext).sendBroadcast(intent)
// Updates notification content if this service is running as a foreground
// service.
if (serviceRunningInForeground) {
notificationManager.notify(
NOTIFICATION_ID,
generateNotification(currentLocation))
}
} else {
Log.d(TAG, "Location information isn't available.")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment