mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
implement request_location_update via push notifications (#333)
This commit is contained in:
parent
33ffe4a70c
commit
48dd9192bb
|
@ -32,6 +32,8 @@ class LocationBroadcastReceiver : BroadcastReceiver() {
|
|||
companion object {
|
||||
const val ACTION_REQUEST_LOCATION_UPDATES =
|
||||
"io.homeassistant.companion.android.background.REQUEST_UPDATES"
|
||||
const val ACTION_REQUEST_ACCURATE_LOCATION_UPDATE =
|
||||
"io.homeassistant.companion.android.background.REQUEST_ACCURATE_UPDATE"
|
||||
const val ACTION_PROCESS_LOCATION =
|
||||
"io.homeassistant.companion.android.background.PROCESS_UPDATES"
|
||||
const val ACTION_PROCESS_GEO =
|
||||
|
@ -55,6 +57,7 @@ class LocationBroadcastReceiver : BroadcastReceiver() {
|
|||
ACTION_REQUEST_LOCATION_UPDATES -> setupLocationTracking(context)
|
||||
ACTION_PROCESS_LOCATION -> handleLocationUpdate(context, intent)
|
||||
ACTION_PROCESS_GEO -> handleGeoUpdate(context, intent)
|
||||
ACTION_REQUEST_ACCURATE_LOCATION_UPDATE -> requestSingleAccurateLocation(context)
|
||||
else -> Log.w(TAG, "Unknown intent action: ${intent.action}!")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
|
|||
import com.google.firebase.messaging.FirebaseMessagingService
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import io.homeassistant.companion.android.R
|
||||
import io.homeassistant.companion.android.background.LocationBroadcastReceiver
|
||||
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor
|
||||
import io.homeassistant.companion.android.domain.integration.IntegrationUseCase
|
||||
import io.homeassistant.companion.android.webview.WebViewActivity
|
||||
|
@ -62,11 +63,27 @@ class MessagingService : FirebaseMessagingService() {
|
|||
}
|
||||
|
||||
remoteMessage.notification?.let {
|
||||
if (it.body == "request_location_update") {
|
||||
Log.d(TAG, "Request location update")
|
||||
if (actions.size != 0) {
|
||||
Log.w(TAG, "Ignoring received actions since location update was requested")
|
||||
}
|
||||
requestAccurateLocationUpdate()
|
||||
return
|
||||
}
|
||||
|
||||
Log.d(TAG, "Message Notification: ${it.title} -> ${it.body}")
|
||||
sendNotification(it.title, it.body!!, actions)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestAccurateLocationUpdate() {
|
||||
val intent = Intent(this, LocationBroadcastReceiver::class.java)
|
||||
intent.action = LocationBroadcastReceiver.ACTION_REQUEST_ACCURATE_LOCATION_UPDATE
|
||||
|
||||
sendBroadcast(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and show a simple notification containing the received FCM message.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue