Created
April 26, 2020 12:33
-
-
Save Lavanyagaur22/77dc574908b9ad78e162cbb2577c0a7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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