Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a notification command to launch an activity #1327

Merged
merged 4 commits into from Jan 29, 2021

Conversation

dshokouhi
Copy link
Member

@dshokouhi dshokouhi commented Jan 28, 2021

Summary

Fixes: #1326

A new command command_activity is added to handle this specific intent as we need to do several things to properly launch an activity. The title must contain the URI to send to the app. The channel must be used to set the package name of where the intent needs to be sent to. The group must be set the intending action string. We handle generating the URI and launching the activity with the intent.

Example:

message: command_activity
title: "geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA"
data:
  channel: "com.google.android.apps.maps"
  group: "android.intent.action.VIEW"
message: command_activity
title: "google.navigation:q=arbys"
data:
  channel: "com.google.android.apps.maps"
  group: "android.intent.action.VIEW"

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#442

Any other notes

FCM PR: home-assistant/mobile-apps-fcm-push#36

@mdegat01
Copy link

Nice! Yea that is clearly a lot easier to use then my suggestions haha.

@dshokouhi
Copy link
Member Author

dshokouhi commented Jan 28, 2021

Looks like the checks got stuck, going to close and re-open

Edit: either something is down or I am not patient enough 😆

@dshokouhi dshokouhi closed this Jan 28, 2021
@dshokouhi dshokouhi reopened this Jan 28, 2021
@dshokouhi dshokouhi closed this Jan 28, 2021
@dshokouhi dshokouhi reopened this Jan 28, 2021
Comment on lines 416 to 453
var mode = data["channel"]
val validModes = listOf("d", "b", "l", "w")
if (mode !in validModes)
mode = "d"
val navigate = "google.navigation:q=$title&mode=$mode"
val mapsIntentUri = Uri.parse(navigate)
val mapIntent = Intent(Intent.ACTION_VIEW, mapsIntentUri)
mapIntent.setPackage("com.google.android.apps.maps")
mapIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(mapIntent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to hard link to google navigation. Maybe use the common intent? I know it might not be identical but this way if someone doesn't use Google Maps this will still work for them.
https://developer.android.com/guide/components/intents-common#ViewMap

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok so a special command that starts an activity with Intent.ACTION_VIEW preset?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok think i got it generic enough now lol

@dshokouhi dshokouhi changed the title Add a notification command to navigate to a location Add a notification command to launch an activity Jan 28, 2021
@dshokouhi
Copy link
Member Author

Per: https://developer.android.com/guide/components/intents-common#Music this might also fix: #1148 as a temporary workaround until we set something up similar for actionable notifications.

@JBassett JBassett merged commit bf895bb into home-assistant:master Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notification command for google maps intent
4 participants