android icon indicating copy to clipboard operation
android copied to clipboard

Add Ability to add App Links that can be opened.

Open seanmccabe opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. Possibly, slightly incorrect behaviour from the app, but its also not documented supported behaviour. See below.

Describe the solution you'd like Would like to be able to add app links to notifications so that apps can be opened using their prescribed links.

i.e. Opening BG Stats app requires using a url like so:

bgstats://app.bgstatsapp.com/addPlay.html?gameId=36218

However at the moment sending this link in a notification and clicking it results in HA opening and then getting a 404 error. Home Assistant should only open on relative likes with /lovelace/... and then open other links as per the system, or do nothing.

http links opening browser for example.

app::// links do work as documented, but unfortunately cannot send additional parameters with these kind of links.

I'm going to assume here BG Stats for example are doing things correctly, and there should be greater scope for HA to support link types in notifications, but happy to be corrected if wrong.

Describe alternatives you've considered, if any No alternatives.

Additional context Example of requirements etc. can be found at BG Stats Support page.

seanmccabe avatar Sep 16 '22 05:09 seanmccabe

Looks like they offer 2 formats, https and bgstats. As long as BG Stats is registered to open both of these links then the first one should work. You can check the default links by looking at the app info link, might want to check if its checked off if its not working. For example the android app is registered for a couple HA specific URLs.

The link is a simple request URL with this format:
https://app.bgstatsapp.com/createPlay.html?data=<data>

Alternatively, bgstats://app.bgstatsapp.com/createPlay.html?data=<data> works as well.

I am not sure if we can improve upon our current code however we should not be looking for the bgstats:// prefix specifically. I think this might be why they offer 2 types of URLs because one can be handled internally while the other is external. Alternatively what we can do is add support for the intent scheme URL in notifications so you can build your own intent like their example. However I think the https link should suffice here.

dshokouhi avatar Sep 16 '22 06:09 dshokouhi

Forgot to mention but you can also use command_activity and command_broadcast_intent to achieve a similar result. The only difference being those commands get processed immediately. What I mentioned up above will occur after the user clicked on the notification itself or an action button.

dshokouhi avatar Sep 16 '22 07:09 dshokouhi

Looks like they offer 2 formats, https and bgstats. As long as BG Stats is registered to open both of these links then the first one should work. You can check the default links by looking at the app info link, might want to check if its checked off if its not working. For example the android app is registered for a couple HA specific URLs.

The link is a simple request URL with this format:
https://app.bgstatsapp.com/createPlay.html?data=<data>

Alternatively, bgstats://app.bgstatsapp.com/createPlay.html?data=<data> works as well.

I am not sure if we can improve upon our current code however we should not be looking for the bgstats:// prefix specifically. I think this might be why they offer 2 types of URLs because one can be handled internally while the other is external. Alternatively what we can do is add support for the intent scheme URL in notifications so you can build your own intent like their example. However I think the https link should suffice here.

Thanks for looking at this, basically my issue is, is the https one works, kinda. It doesn't open the app, but displays a webpage where it is supposed to open the app, but it doesn't work, but it does have a click here link to then open the app. However, clicking this link then results in the additional URL parameters being dropped, so at which point may as well just stick with opening the app with app:// So the https link doesn't work as intended. Ideally want to afford opening a browser app, to then open another app.

Using the bgstats:// option just results in Home Assistant opening and presenting a 404 not found page, so that doesn't work either.

Forgot to mention but you can also use command_activity and command_broadcast_intent to achieve a similar result. The only difference being those commands get processed immediately. What I mentioned up above will occur after the user clicked > on the notification itself or an action button.

Mmm...so possible way around it would be to use an action command to trigger an automation in HA to then send the _command_activity_ or command_broadcast_intent to open the app, but would just be trying to figure out which device sent that command (haven't check docs, but assume that is sent with the action).

Only issue I see is there is no mention on that page of supporting intents. Unless that is what the bgstats:// bit is. I'm not an Android dev, so its a bit beyond me.

seanmccabe avatar Sep 17 '22 04:09 seanmccabe

Ok so just discovered that in the bg stats app on Android you have to actually turn on the the Open supported links and then select which links in the Supported web addresses section. For some reason these aren't turned on by default, at least not for this app, perhaps for others.

Now my https link is working :) Still great for HA to support other app links like bgstats:// where the https:// isn't an option and prevent HA opening when it shouldn't be.

seanmccabe avatar Sep 17 '22 05:09 seanmccabe

Mmm...so possible way around it would be to use an action command to trigger an automation in HA to then send the _command_activity_ or command_broadcast_intent to open the app, but would just be trying to figure out which device sent that command (haven't check docs, but assume that is sent with the action).

Anytime a notification is received on any device an event is sent back to HA, you can use that data to figure out what was sent to whom:

https://companion.home-assistant.io/docs/notifications/notification-received

Only issue I see is there is no mention on that page of supporting intents. Unless that is what the bgstats:// bit is. I'm not an Android dev, so its a bit beyond me.

Oh its there just search the page for intent and you can see the examples :)

    val openUrlIntent = Intent(Intent.ACTION_VIEW, Uri.parse(requestString))
    startActivity(openUrlIntent)

the correct command here would be

message: command_activity
data:
  intent_uri: "bgstats://a/b/c/d"
  intent_action: "android.intent.action.VIEW"
  intent_package_name: "<bgstats_package_name>"

This could also be translated to the intent URI scheme mentioned in the linked PR. The PR basically provides this method in the clickAction and actions so that it can be executed by the user from the notification. Instead of the example above which processes the command as soon as the notification is received on the device

Ok so just discovered that in the bg stats app on Android you have to actually turn on the the Open supported links and then select which links in the Supported web addresses section. For some reason these aren't turned on by default, at least not for this app, perhaps for others.

Should be on by default but that is why I mentioned up above in my post to check that it is enabled :)

dshokouhi avatar Sep 17 '22 19:09 dshokouhi

Still great for HA to support other app links like bgstats:// where the https:// isn't an option and prevent HA opening when it shouldn't be.

My latest commit in #2888 adds a new prefix for deep-link:// where you can add an app link after the prefix and the app will handle it

dshokouhi avatar Sep 17 '22 20:09 dshokouhi