Android 7 & Media Button Events

574 views
Skip to first unread message

David Marden

unread,
Aug 24, 2016, 5:19:22 PM8/24/16
to Tasker
Hi there, I posted about this on reddit before seeing this group linked on the web page.


My most important and beloved Tasker profile/task is very simple. It keeps my car from automatically starting music when I get in.


Profile activates when my phone connections to "SYNC". This part still works, I see the profile activate instantly.


The task is "Media Button Events" > Action: Grab


That part is no longer working after the update to Android 7 on my Nexus 6P. It had been working fine on Android 6/6.0.1. Media button events now pass through uninhibited as if Tasker were not there.

I made sure Tasker wasn't getting killed off or anything and kept it going in the foreground. I see in the notification shade that that profile has activated. It's just not grabbing those media button events.

Pent

unread,
Aug 25, 2016, 5:00:20 AM8/25/16
to Tasker
Try enabling Menu / More / Run Log and check the action is running OK.

In any case, I've noted the problem and will try to reproduce it once I have
a device with N. Unfortunately, this is one of the few times they've launched
a major new version without a new device.

Pent

David Marden

unread,
Aug 25, 2016, 9:42:38 AM8/25/16
to Tasker
So here's the unexpected (to me) result that I got.

If I have the Run Log window open/in the forgeground/focused (i.e. not just running in the background) the task actually seems to work (tried 3 times).

If I have the Run Log enabled but not focused (i.e. it is running in the background) the task does not work and music is played.

Having Tasker set to run in the foreground (so that icon and notification display) does not help (the notification shows the profile active, but music still plays).

The log content seems to be the same either way (in both failing and succeeding situations):  https://www.dropbox.com/s/qq2ucolhptt54lf/2016-08-25%2013.27.11.png?dl=0
2016-08-25 13.27.11.png

Pent

unread,
Aug 26, 2016, 4:18:39 AM8/26/16
to Tasker
Sounds like 7 is only allowing apps to grab media events if they have the
foreground activity.

You could try showing a scene then doing the grab.

I unfortunately don't have a device to test on yet.

Pent

David Marden

unread,
Aug 26, 2016, 9:49:46 AM8/26/16
to Tasker
Ok, so I *THINK* I have it working... it needs more testing than I can do right now while in my office, but I will report back later.

Initially, I just setup a scene to display a message for a few seconds but it seemed like this only worked if the screen was on.  If it was off, the grab action failed to be effective.

So now I have the task setup for a 1 second HTML popup to wake the screen, then the text scene displays, media button grab, wait 5 seconds, kill scene.

Not sure if this is proper or elegant, but it does SEEM to work in my very limited testing.  I will test more after work.

David Marden

unread,
Aug 29, 2016, 2:48:54 PM8/29/16
to Tasker
So after testing this a few days, it only works sometimes.

I cannot quite nail down exactly what makes it succeed or fail, but... it's about 50/50 for me.  It sort of seems like if I locked my phone with an app open, that might impact it, but... not always, so... I don't really know.

Not sure what else to try at this point, so I will just hope for improvement once more testing and maybe an update is possible.

Pent

unread,
Aug 31, 2016, 6:20:18 AM8/31/16
to Tasker
Maybe a timing thing, you could put a small Wait action after showing the scene.

Anyway, I'll probably have to build some similar method into Tasker, so I wouldn't
worry too much if you can't get it working.

Pent

Pent

unread,
Nov 3, 2016, 7:14:42 AM11/3/16
to Tasker
Turns out there's a whole new API for dealing with this. I've implemented
it and things appear to work without needing to jump through hoops now.

Pent

David Marden

unread,
Nov 3, 2016, 7:35:47 AM11/3/16
to Tasker
Awesome, thanks for following up... I'll look for the update.  I did eventually get it working with, as you described it, some hoop jumping.

David Marden

unread,
Dec 11, 2016, 1:14:04 AM12/11/16
to Tasker
Hey there! Is this new implementation in the current (4.9b6m)?

With the new beta, I cannot get media button grab to work with or without the hoop jumping that worked in 4.8. Running 7.1.1.

If I revert back to the release version, media button grab still works with the hoop jumping.

Thanks!

Pent

unread,
Dec 13, 2016, 3:43:17 AM12/13/16
to Tasker

Hey there! Is this new implementation in the current (4.9b6m)?

Yes.
 

With the new beta, I cannot get media button grab to work with or without the hoop jumping that worked in 4.8.  Running 7.1.1.


I also can't get it working again, I'm a bit stumped,
I spent quite a while on it a few weeks ago and had it working well.

Think I'll give up for now and try again tomorrow :-(

Pent

David Marden

unread,
Dec 13, 2016, 7:44:20 AM12/13/16
to Tasker
I also can't get it working again, I'm a bit stumped,
I spent quite a while on it a few weeks ago and had it working well.

Think I'll give up for now and try again tomorrow :-(



Well... on one hand, I am glad it is not just me.  On the other hand, sorry it is troubling you... I appreciate your effort. 

Pent

unread,
Dec 16, 2016, 3:46:09 AM12/16/16
to Tasker
Spent hours more on this and still can't get back to where I was before,
have to give up.

It seems to work fine for me on 7 if I show a dialog scene over the top though, same
as your original workaround, or if the app which currently is intercepting the
buttons is not foreground.

Pent

David Marden

unread,
Dec 16, 2016, 9:13:46 AM12/16/16
to Tasker


On Friday, December 16, 2016 at 3:46:09 AM UTC-5, Pent wrote:
Spent hours more on this and still can't get back to where I was before,
have to give up.

I understand and appreciate the effort.
 
It seems to work fine for me on 7 if I show a dialog scene over the top though, same
as your original workaround, or if the app which currently is intercepting the
buttons is not foreground.

Yes, the old workaround method is working again in 4.9b7 (it was not working in 4.9b6).  Thank you. 

Oliver McIrwin

unread,
Aug 3, 2017, 4:36:23 PM8/3/17
to Tasker
Hello, Just wanted to ask if there have been any updates to this. I too am trying to keep audio for automatically playing when Bluetooth is connected to my car. 

This is generally what I have. It worked perfect the first time, but hasnt worked since.

Profile: Connected To Car (2)
   
State: BT Connected [ Name:HandsFreeLink Address:* ]
Enter: Anon (3)
    A1
: Popup [ Title: Text:Wake Background Image: Layout:Popup Timeout (Seconds):1 Show Over Keyguard:On ] If [ %SCREEN ~ off ]
    A2
: Media Button Events [ Action:Grab Use New API:On ]


Profile: Play In Car (14)
   
State: Media Button [ Button:Play Held Down:Off Grab:Off Stop Event:Off ]
   
State: BT Connected [ Name:HandsFreeLink Address:* ]
Enter: Anon (19)
    A1
: Media Button Events [ Action:Grab Use New API:On ]

Andrea Borgia

unread,
Aug 6, 2017, 1:12:26 PM8/6/17
to Tasker
Il giorno giovedì 3 agosto 2017 22:36:23 UTC+2, Oliver McIrwin ha scritto:
 
Hello, Just wanted to ask if there have been any updates to this. I too am trying to keep audio for automatically playing when Bluetooth is connected to my car.
This is generally what I have. It worked perfect the first time, but hasnt worked since.

What is the advantage of using "Media button"? I'm using "Media Control / Play" and it always works, with Google Play Music.
I have trouble setting the volume reliably but that's another story (and another post).

Andrea.
Reply all
Reply to author
Forward
0 new messages