Media buttons recognize only on screen on

Post your questions and help other users.

Moderator: Martin

Sergey_777-s
Posts: 42
Joined: 17 Sep 2019 08:30

Media buttons recognize only on screen on

Post by Sergey_777-s » 07 Dec 2019 12:07

using hardware key event I try to execute flow when MEDIA_PREVIOUS on my Bluetooth device pressed. When screen is on all works correctly! But on turn off screen automagic not recognize MEDIA_PREVIOUS button pressing on hardware phone keys all OK, problem only with the MEDIA_* keys on blank screen. How to fix this problem?

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Media buttons recognize only on screen on

Post by Desmanto » 07 Dec 2019 17:17

Hardware key event trigger works using accessibility services, which get suspended when the screen is off. So none of the hardware key event flow can be triggered when screen off. For the media button, you can try trigger Media Button Event (Experimental) instead. It also has all the media button there and should work in screen off.

However other media app can steal the media button focus. So if you use the buttons in call/music/video player, from time to time, you might need to use action Reregister Media Button Receiver to make Autoamgic can react to the media button again. Or simply use action sound - silent, so Automagic gain the audio focus and media button again.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Sergey_777-s
Posts: 42
Joined: 17 Sep 2019 08:30

Re: Media buttons recognize only on screen on

Post by Sergey_777-s » 07 Dec 2019 22:03

I re-register button service but nothing works on screen off

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Media buttons recognize only on screen on

Post by Desmanto » 08 Dec 2019 16:33

I have tried with my bluetooth headset, pressing media play/pause, next and prev, works at mine at screen off. Do you have any kind app of that can steal the media button focus at screen off? Try first at the flow and setup a very simple flow. Use trigger Media button event : all button, and vibrate. At screen on, try and see if it works. Then turn screen off, immediately test again.

If at screen on, it doesn't react, you can try to play a silent sound first at automagic. This just to ensure Automagic has the media button focus.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Sergey_777-s
Posts: 42
Joined: 17 Sep 2019 08:30

Re: Media buttons recognize only on screen on

Post by Sergey_777-s » 10 Dec 2019 22:35

I tryed this, when, for example I get event play/pause on my Bluetooth device I setup automatic to vibrate, when screen on - my phone vibrate when I press play button. But when I press play button on off screen the phone doesn't vibrate and starts aimp player an I listen the music but must be vibration

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Media buttons recognize only on screen on

Post by Desmanto » 11 Dec 2019 16:42

It seems the aimp got the focus as soon as the screen off. Do you test this when the music is playing? Can you try to exit AIMP and then force stop it first to try again? Or maybe even further, uninstalling (if you don't have any setting/playlist need to be saved).

I try this with minilyric open, not playing sound. Screen off, bluetooth media button still works. Once I tap play at minilyric, all focus now changed to minilyric, screen on and off. I play notif sound at Automagic and now shifted back to Automagic.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Sergey_777-s
Posts: 42
Joined: 17 Sep 2019 08:30

Re: Media buttons recognize only on screen on

Post by Sergey_777-s » 12 Dec 2019 20:05

No aimp isn't a problem, when I kill aimp and press forward button on bluetooth when music isn't playing automagic react only when screen is on, on off screen nothing happens

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Media buttons recognize only on screen on

Post by Desmanto » 13 Dec 2019 18:51

What is your current phone and android version? It seems something is limiting the screen off capability of Automagic. Try to grant Automagic device administrator permission. It seems you also need to enable debug log in Automagic and check it later to see if there is any event when screen off. You might want to try to your other device if you have secondary/older device with different android version.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Sergey_777-s
Posts: 42
Joined: 17 Sep 2019 08:30

Re: Media buttons recognize only on screen on

Post by Sergey_777-s » 15 Dec 2019 23:37

It's 7 version of Android with all permissions and no events in the debug log with screen off

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Media buttons recognize only on screen on

Post by Desmanto » 16 Dec 2019 17:43

I assume you have whitelisted Automagic from the battery optimization. But some brand have another killer app in the background which stop all background activity after the screen is off. See : https://dontkillmyapp.com/ and find the instruction for your device brand.

You need to try on other device to see if that is the case. It is working at mine, I don't use any task killer and have whitelisted automagic from any kind of battery optimization or possible limiter.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply