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

Hi! Did anyone get this to work with VLC for android? Their Intents are documented here, but I can’t seem to get it right.

I tried

data:
  message: command_activity
  data:
    intent_package_name: org.videolan.vlc
    intent_action: android.intent.action.VIEW
    intent_uri: https://www.youtube.com/watch?v=dQw4w9WgXcQ

And some other variations. Any input on whats wrong here? The example on the VLC wiki also sets a type together with a URI, but I’m not sure how to do that using HASS.

EDIT: The Error message is a toast saying that the intent could not be started

Apparently, the url goes into extra for VLC
Try:

data:
  message: command_activity
  data:
    intent_package_name: org.videolan.vlc
    intent_action: android.intent.action.VIEW
    intent_extras: "url:https://www.youtube.com/watch?v=dQw4w9WgXcQ"

I don’t know how to set data and type, though, if required. I’m afraid that’s not currently supported.

1 Like

should be intent_uri for this

intent_type should be used for this

2 Likes

Right. Didn’t realize “setDataAndType” was just a helper :roll_eyes:

1 Like

Very interesting thread. Just what I was looking for.

The app I was trying to get working is WiGle. They have the following post HOW TO: Start/Stop Scan/Pause WiGLE WiFi Android when a battery, location, network, or other event happens - WiGLE.net where they discuss what’s needed to get Tasker to perform the scan.

I’ve tried the following, with and without the intent_class_name parameter without any success.

service: notify.mobile_app_s23
data:
  message: command_activity
  data:
    intent_package_name: net.wigle.wigleandroid
    intent_action: net.wigle.wigleandroid.SCAN
    intent_class_name: net.wigle.wigleandroid.listener.ScanControlReceiver

In the logs I get

02-13 22:19:18.291 23154 27928 D WebSocketRepository: Websocket: onMessage (text)
02-13 22:19:18.291 23154 27928 D WebSocketRepository: Message number 706 received
02-13 22:19:18.294 23154 23154 D MessagingService: Processing device command
02-13 22:19:18.298 23154 23154 E MessagingService: Unable to send activity intent please check command format
02-13 22:19:18.298 23154 23154 E MessagingService: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=net.wigle.wigleandroid.SCAN flg=0x10000000 pkg=net.wigle.wigleandroid }
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2252)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1878)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.app.ContextImpl.startActivity(ContextImpl.java:1174)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.app.ContextImpl.startActivity(ContextImpl.java:1145)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.content.ContextWrapper.startActivity(ContextWrapper.java:445)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingManager.processActivityCommand(MessagingManager.kt:1703)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingManager.handleDeviceCommands(MessagingManager.kt:693)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingManager.access$handleDeviceCommands(MessagingManager.kt:102)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at io.homeassistant.companion.android.notifications.MessagingManager$handleMessage$4.invokeSuspend(MessagingManager.kt:424)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.os.Handler.handleCallback(Handler.java:958)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.os.Looper.loopOnce(Looper.java:230)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.os.Looper.loop(Looper.java:319)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at android.app.ActivityThread.main(ActivityThread.java:8893)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at java.lang.reflect.Method.invoke(Native Method)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
02-13 22:19:18.298 23154 23154 E MessagingService: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
02-13 22:19:18.303 23154 23154 I Toast   : show: caller = io.homeassistant.companion.android.notifications.MessagingManager.processActivityCommand$lambda$41:1722 
02-13 22:19:18.306 23154 23154 I Toast   : show: isDexDualMode = false
02-13 22:19:18.306 23154 23154 I Toast   : show: contextDispId = 0 mCustomDisplayId = -1 focusedDisplayId = 0 isActivityContext = false
02-13 22:19:18.577 23154 21905 I SensorReceiver: Sensor updates and sync completed
02-13 22:19:18.878 23154 21906 I SensorReceiver: Sensor updates and sync completed
02-13 22:19:18.878 23154 21906 I SensorReceiver: Sensor updates and sync completed
02-13 22:19:18.882 23154 21905 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true
02-13 22:19:19.013 23154 23154 D SensorReceiver: Received intent: io.homeassistant.companion.android.UPDATE_SENSORS
02-13 22:19:19.015 23154 23154 D LastUpdate: Last update is io.homeassistant.companion.android.UPDATE_SENSORS
02-13 22:19:19.023 23154 21905 D ServerConnectionInfo: localUrl is: true, usesInternalSsid is: true, usesWifi is: true

Any idea what I’m doing wrong? This whole thing looks so much more powerful once you start looking at what you can do. It just isn’t as easy to get the intents right for everything to work.

-P

try changing this to command_broadcast_intent and also drop intent_class_name as its not included in their example.

As I started going through some more documentation I saw the command_broadcast_intent and tried it.

service: notify.mobile_app_s23
data:
  message: command_broadcast_intent
  data:
    intent_package_name: net.wigle.wigleandroid
    intent_action: net.wigle.wigleandroid.SCAN

I tried it and it worked. As I was coming to reply to my post, I saw you’d replied as well… Thank you. You can add this to your list above.

I can now automatically start WiGle and have it start scanning once I leave Home zone and of course, stop scanning when I get back into Home zone.

-P

1 Like

For playing video / music in MX Player in android.

service: notify.mobile_app_xxxxx
data:
          message: "command_activity"
          data:
            intent_package_name: "com.mxtech.videoplayer.pro"
           # intent_package_name: "com.mxtech.videoplayer.ad" # free version
            intent_action: "android.intent.action.VIEW"
            intent_uri: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"

Awesome thread! Thanks for the help.

I have another App I’m trying to start via an Intent from HA and can’t quite get it to work. These are the instructions from the developer:

Start:

* Action: `ACTION_START`
* Extra: `EXTRA_HOST:ip_here`
* Extra: `EXTRA_PORT:1704`
* Package: `de.badaix.snapcast`
* Class: `de.badaix.snapcast.SnapclientService`
* Target: `Service`

So this is to launch a service, not an activity. My current approach is this:

service: notify.mobile_app_XXX
metadata: {}
data:
  message: command_activity
  data:
    intent_action: android.intent.action.START
    intent_package_name: de.badaix.snapcast
    intent_class_name: de.badaix.snapcast.SnapclientService
    intent_extras: "EXTRA_HOST:192.168.1.5,EXTRA_PORT:1704"

, but it doesn’t work. The phone says the activity intent could not be sent. command_broadcast_intent doesn’t work either, with no error message at all. Any idea if I need to do something different to start a service, rather than an activity?

starting a service is not currently supported but you can submit a feature request on github for it. The app needs to implement the following feature to work with it.

https://developer.android.com/reference/android/content/Context#startService(android.content.Intent)

Calling a broadcast intent that needs action,component,and extras is a pain even with using the activity

alias: newpipe
sequence:
  - service: notify.mobile_app_phone
    data_template:
      message: command_broadcast_intent
      data:
        intent_action: android.intent.action.SEND
        intent_package_name: org.schabi.newpipe
        intent_class_name: org.schabi.newpipe/.RouterActivity
        intent_extras: android.intent.extra.TEXT "123"

Cant make this to work

Calling the activity from terminal or adb works

su -c am start -a android.intent.action.SEND -n org.schabi.newpipe/.RouterActivity --es "android.intent.extra.TEXT" "123"

not certain this is the correct format for teh class name, try to drop the /

this does not even follow the documentation

https://companion.home-assistant.io/docs/notifications/notification-commands#broadcast-intent

intent_extras: "android.intent.extra.TEXT:123"

Tbh i’m not sure about yhe “clas” part.

org.schabi.newpipe/.RouterActivity is the intent componenet and passed with -n in adb.

I dont know how to pass that in the HASS script.

I read from Notification Commands | Home Assistant Companion Docs

That Some applications also require the class or component to be provided. For these applications you will need to provide the package as the intent_package_name and the full and complete class name under the intent_class_name parameter. You will need to know what class name to provide as each application is different.

Fixed the intent_extras part and removed the /

It returns no errors now but the script runs without effect.

Thanks

When I use the Android ADB Bridge on my new Google TV’s to start YouTubeTV it starts in the browser without asking. My older tv’s asked me whether to use the web or the app. Is there a way to use intents - or some other method - to tell the Bridge to use the app instead of the web?

sounds like maybe you selected browser as default? Try to go in device settings to remove teh default. Also sounds like you are referring to an actual HA core integration and not the companion app?

I couldn’t find a way to change it to App in the device settings. Where would that be?

Looking for some help please. Got adb commands working fine, can sleep/wake my Nvidia Shield. Found the intents on this chat on how to launch spotify, seems to work good. However heres what i am trying to acheive. If anyone could please help guide :pray:.

Launch Amazon Music app and contine playing my playlist.

Found this post, but it didnt open the app on my Shield.

am start -a android.intent.action.VIEW -n com.amazon.bueller.music/com.amazon.music.MainActivity

Thanks in advance!

For Brazilians who want to open the Globo Play app, on the “Globo Ao Vivo” channel, here is a functional intent:

service: remote.turn_on
target:
  entity_id: remote.your_device_here
data:
  activity: https://globoplay.globo.com/tv-globo/ao-vivo/6120663/

I’m trying to get my Home Assistant app to start a timer on my S23 Ultra (as a work around to Google breaking assistant) and am just getting notifications rather than the action performed.

Simplifying back to an MVP detailed in the documentation, to eliminate any Samsung weirdness with the clock app, gets me this call which reproduces the issue:-

service: notify.mobile_app_kev_s_galaxy_s23_ultra
data:
  message: "command_bluetooth"
  data:
    command: "turn_off"

i.e. it simply generates a notification with the text “command_bluetooth” ()

And all the other command_* I’ve tried (command_activity, command_dnd etc) do the same.

Am I missing something obvious? I’ve tried command_bluetooth with and without quotes.

Looking at ADB nothing jumped out:-

> 04-16 10:51:33.488  9905  9905 I NotificationManager: io.homeassistant.companion.android: notify(-430857627, null, Notification(channel=general shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x10 color=0
> xff03a9f4 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)) as user
> 04-16 10:51:33.711  2538  2538 D NotificationReminder: addNotificationRecord record io.homeassistant.companion.android
> 04-16 10:51:33.716  3963  3963 D InterruptionStateProvider:  no Heads up : edgelighting enabled app. 0|io.homeassistant.companion.android|-430857627|null|10372
> 04-16 10:51:33.717  3963  3963 D InterruptionStateProvider:  no Heads up : edgelighting enabled app. 0|io.homeassistant.companion.android|-430857627|null|10372
> 04-16 10:51:33.720  4535  4535 I HoneySpace.NotificationListener: onNotificationPosted io.homeassistant.companion.android: 0|io.homeassistant.companion.android|-430857627|null|10372: 0
> 04-16 10:51:33.720  4535  4535 I HoneySpace.BadgeDataSourceImpl: Get notification count. PackageKey(packageName=io.homeassistant.companion.android, user=UserHandle{0}) - forceBadgeCount: false, notification listener: 1, badge prov
> ider: 0
> 04-16 10:51:33.722  4535  4621 I HoneySpace.PackageEventOperator: [AppsEdgePanel.ViewModel] badge count is updated. io.homeassistant.companion.android/.launch.LaunchActivity#UserHandle{0}|4 : 1
> 04-16 10:51:33.801  3963  3963 D S.S.N.  : entryViewBound parent :0|io.homeassistant.companion.android|-430857627|null|10372
> 04-16 10:51:42.296  2538  4522 W AppOps  : Noting op not finished: uid 10372 pkg io.homeassistant.companion.android code 79 startTime of in progress event=1713261073065
> 04-16 10:51:42.303  2538  4522 D ActivityManager: Received BROADCAST intent 0x19c425f Key{broadcastIntent pkg=io.homeassistant.companion.android intent=act=io.homeassistant.companion.android.background.UPDATE_ACTIVITY cmp=io.homea
> ssistant.companion.android/.sensors.ActivitySensorManager flags=0x2000000 u=0} requestCode=0 sent=0 from uid 10236

As far as I can tell all the relevant permissions are turned on (screenshots below) and there are no pending updates in the Play Store (2024.4.1-full)

All Permissions:-

Home Assistant App Info:-

Appear on top:-

The documentations you link to says:

Unless you downgraded, it ain’t going to work