Android Intents - Sending & Receiving List (Starting Activities too!)

Thanks for the quick response.

I did read the docs. That is how I have come to try this. I obviously didn’t understand them fully though. I also followed the spotify links but didn’t understand fully the coding as they weren’t specifically referring to the HA app.

The intent, com.spotify.music.MainActivity came from Fully Kiosk which uses intents to launch apps and works from Fully so I guessed it was correct.

I have changed the tag to yours and removed the .MainActivity from the channel.

It still doesn’t work and errors with the same error.
have you any further suggestions?
Thanks

According to the links for spotify you probably need to specify the album or artist. You may need to play around until it actually loads honestly. Make sure the permission is granted as well.

I saw that one of the links were trying to play a track or album but that is not what I would like to do. I just want to launch the app.
The second links asks how to do just that but Spotify support didn’t understand the question so gave a poor answer.

I have seen on other threads where people are using REST as well as Intents from HA to Fully Kiosk to launch Spotify
The intent they are using is com.spotify.music so that must be correct
From the links, the activity is ACTIVITY_VIEW so the tag: android.intent.action.VIEW must be correct as well

When i tried the example intent in the docs (com.google.android.apps.maps) it worked a treat.
So what permissions were you mentioning that I should grant?

Thanks again

if it works for one intent then you already granted it. its the draw over other apps permission.

Try this:

service: notify.mobile_app_<mymobile>
data:
  message: command_activity
  data:
    intent_uri: "spotify:album"
    intent_package_name: com.spotify.music
    intent_action: "android.intent.action.VIEW"
1 Like

Doh!

title: "spotify:album"

That works great. I would never have thought of that.

Thank You

I believe its because Spotify requires to receive some data which is why you are seeing the toast message. Its tough to tell what is exactly required per intent but we can at least notify the user when it fails :slight_smile:

I need a little push in the right direction now…

I’m trying to make HA send an sms from my phone.

service: notify.mobile_app_andreas
data:
  message: "command_activity"
  title: "smsto:0123456789"
  data:
    channel: "com.google.android.apps.messaging"
    tag: "android.intent.action.VIEW"
    group: "address:0123456789,sms_body:TEST"

This opens the sms/messaging app with a prefilled phone number (0123456789) and the message body TEST.
But how do I send it?
I want it all to happen in the background. Is it even possible?

...
tag: "android.intent.action.SENDTO"
...

Gives the same result :frowning:

Could it be: https://stackoverflow.com/a/13491005/5159168
Now Permissions open your AndroidManifest.xml and add below line
<uses-permission android:name="android.permission.SEND_SMS"/>
and its done…

The app is not allowed to send sms?

You may need to use tasker to send the actual message as this is as far as the intent goes, it just composes the message. Same with email.

https://developer.android.com/guide/components/intents-common#SendMessage

To initiate an SMS or MMS text message

Thanks.
But I can’t make it with Tasker either.
I (perhaps just me) can’t send variables to Tasker that is then transferred to the sms.
Like phone number, body. It works if I have a predefined sms to send.

Not sure how to implement this: AlarmClock  |  Android Developers

Would that be possible? I tried this, but doesn’t do anything

  action:
    - service: notify.mobile_app_pixel_5
      data:
        message: command_broadcast_intent
        title: "android.provider.AlarmClock.ACTION_SET_ALARM"
        data:
          channel: "android.provider.AlarmClock"

—edit—
This seems to work! Now optimize it further:

  action:
    - service: notify.mobile_app_pixel_5
      data:
        message: command_activity
        data:
          channel: "com.google.android.deskclock"
          tag: "android.intent.action.SET_ALARM"

—edit—2
Unfortunately the Alarm app keeps popping up asking for the time the alarm has to be set to. Even when adding these extras.

  action:
    - service: notify.mobile_app_pixel_5
      data:
        message: command_activity
        data:
          channel: "com.google.android.deskclock"
          tag: "android.intent.action.SET_ALARM"
          group: "EXTRA_SKIP_UI:true,EXTRA_HOUR:10,EXTRA_MINUTES:20,EXTRA_MESSAGE:Kantoor"

Anyone knows what’s going wrong here?

I think those extra names are wrong. Those are the constants defined in the AlarmClock provider.

You need the string values of those constants, such as “android.intent.extra.alarm.SKIP_UI” for EXTRA_SKIP_UI.

These should all be listed in the AlarmClock documentation:

1 Like

Here’s the script I use to set my alarm. You can use it too, just change name of the service for your phone. It takes hour, minutes, offset and name as parameters, calculates the time to set the alarm at as hour + minutes + offset and then makes the appropriate notification command for sleep as android.

I have an automation which looks at my calendars every night at 10pm, figures out the first event I have the next morning and then sets my alarm 10 minutes before it begins lol

alias: Set Mike's alarm
description: Add an alarm on mike's phone
fields:
  hour:
    description: Hour for alarm(24-hour clock)
    example: 6
  minutes:
    description: Minutes for alarm
    example: 30
  offset:
    description: Minutes to offset specified time by
    example: -10
  name:
    description: Name/message for alarm
    example: Wakeup
sequence:
  - service: notify.mobile_app_mikes_phone
    data:
      message: command_activity
      data:
        tag: android.intent.action.SET_ALARM
        group: >-
          {% set pre = 'android.intent.extra.alarm.' %} {% set time =
          strptime(hour | string + ':' + minutes | string, '%H:%M') +
          timedelta(minutes=offset) %} {% set extras = ['HOUR:' +
          time.strftime('%-H'), 
             'MINUTES:' + time.strftime('%-M'), 
             'MESSAGE:' + name | regex_replace('[,:]', ''),
             'SKIP_UI:true'] %}
          {{ pre + extras | join(',' + pre) }}
mode: single
icon: 'mdi:alarm'

I should probably make this script into a blueprint come to think of it. Maybe this weekend.

3 Likes

This worked! Not very clear in the Companion documentation though, where the sample says:

automation:
  - alias: Send broadcast intent with extras
    trigger:
      ...
    action:
      - service: notify.mobile_app_<your_device_id_here>
        data:
          message: "command_broadcast_intent"
          title: "com.urbandroid.sleep.alarmclock.ALARM_STATE_CHANGE"
          data:
            channel: "com.urbandroid.sleep"
            group: "alarm_label:work,alarm_enabled:false"

But I am happy and was going to create something like @Steven_Rollason. Setting my alarm clock according to if I will be going to office, if my wife is working, etc.

The companion docs are correct here. The actual issue is that the example provided is only for Sleep as Android as mentioned and linked in the docs. The example provided by @Steven_Rollason was for the stock google app.

I didn’t say the docs are incorrect. It’s just not very clear by using (only) this example in my opinion.

Unfortunately there is no easy way to accurately list and describe everything. Every app and every intent has its own required set of data which is why we mention you’ll have to play around with it to get things right. The examples provided are only an example to show you how it works. This is also considered an advanced feature due to that.

I tried many of intents and none of them works with Samsung Galaxy Watch.
I wanted to read battery level of my smartwatch.
Maybe someone made this?

I tried:

android.bluetooth.device.BATTERY_LEVEL_CHANGED
android.bluetooth.device.extra.BATTERY_LEVEL
com.samsung.android.gearoplugin
android.bluetooth.BluetoothAdapter

None of them doesn’t appears in history, or event listener.

Hi all,
I’m looking for a way to launch the HA app on a specific view, is it possible ?
I saw there are these class names but haven’t found one useful for my purpose.

Use shortcuts to do that

1 Like

Thank you,
I didn’t know that possibility, at the end it is very easy:

service: notify.mobile_app_nexus_10
data:
  message: command_webview
  title: /lovelace/outdoor-camera-view

So now I can have the tablet sense the noise of the door bell through its own microphone via RTSP and the automation that change the view for some time before going back to the normal view :slight_smile: amazing!
Best regards,
Mike