How to Enable Media Playback Nav Bar Controls in Android O when Playing Music

The Android O Developer Preview has only been out for a week, but we’re quickly discovering more and more potential uses for all of the new features. One of the features we’ve been most excited about is the new navigation bar customizer found in System UI Tuner.

On initial inspection, Google’s implementation seems quite barebone. While you are able to add a new navigation key to the left and right of your existing keys, any key that you add will be permanently situated on your navigation bar. Unfortunately, that makes this feature useless for many people, as many of the keys you would want on the nav bar only work under specific circumstances. But as we’ve shown you before, it is in fact possible to enable specific nav bar keys under your own customizable conditions. In this tutorial, we’ll show you how to enable media playback control buttons in your navigation bar when Google Play Music, or any other music app, is playing music.

Thanks Eli Irvin for testing this for me, and capturing this screen recording!

Enable Media Playback Nav Bar Controls

Tasker is necessary because it is the automation app we’re using to detect what application we’re in and send commands through the SecureTask plug-in, which is what will handle changing our navigation bar. Once you’ve installed these applications, we need to set them up.

In order to detect when music is being played, we need to enable Notification Access for the Notification Listener plugin. Doing so is very quick, simply go to Settings and search for “notification access” in the search bar. Open the settings page, look for Notification Listener, and grant it access to read notifications.

Next, we need to grant SecureTask the ability to modify system settings on our device. In order to do so, we have to grant SecureTask a special permission known as WRITE_SECURE_SETTINGS which is normally inaccessible to regular applications, but can be granted manually by a user through the use of ADB. Thus, you’ll need to have ADB up and running on your machine to get this working. Fortunately, granting this permission is a one-time thing, and we’ll be using SecureTask in future Android O-related tutorials, so I definitely advise you doing this now. If you’ve followed my previous tutorials where I told you to install AutoTools, SecureTask is less feature-filled but it has just enough for our needs here.

Setting up ADB

The first thing you’ll need to do is download the ADB binary for your particular OS. You can do so here. Once you’ve downloaded them, you need to then make sure you have the proper driver if you’re on Windows.

Once you’ve extracted the binary to a separate folder and have installed the driver, we need to next enable USB Debugging on the smartphone. In order to do so, open up Settings and go to About Phone. Tap on Build Number 7 times until you get a dialog telling you that you’ve unlocked Developer Options. You can access Developer Options in Settings now. Apparently in Android O, you have to enter your pin/password before you can open Developer Options. Do so and look for USB Debugging, then enable it.

Now plug in your phone and open up a command prompt in the same directory where you extracted the ADB binary. (Windows users, hold shift+right-click in that folder and select “open command prompt here.”) Type adb devices into the command prompt. You’ll see a message that the ADB server is being started, then on your phone you’ll see a prompt asking you to grant your computer ADB access. Accept it. Now when you enter adb devices into the command prompt, you should see your device’s serial number, if so then you were successful.

Granting WRITE_SECURE_SETTINGS to SecureTask

With an ADB command prompt opened up, enter the following command to grant SecureTask the requisite permission.

SecureTask will now have the ability to modify system settings without root access! Now we’re ready to move on to Tasker.

Setting up the Tasker Profiles

We’ll be creating two separate Tasker Profiles here. One that reacts to when our music player of choice (in my example, Google Play Music) starts music playback (its notification has been posted), and one that reacts to when that same music player’s notification has been dismissed.

Open up Tasker and create a new Profile by pressing the + icon in the bottom right. We’ll start with making a Profile that triggers when the music player’s notification has been posted. Name the Profile “Enable Media Nav Keys” and select an Event Context. Go to Plugin –> Notification Listener –> Notification Listener. For the Notification Event, select Posted and under Apps select the applications that you want to monitor (eg. Google Play Music).

Once you’re done, back out and Tasker will ask you to attach a Task to this Profile. You can name the Task, but it’s not necessary. Just hit the checkmark to enter the Task editing screen. Once you’re in, we’re going to add two Actions to this Task.

A1: Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_left. Value: key(88:com.android.systemui/2131230907). This is KEYCODE_MEDIA_PREVIOUS and will show up as a left arrow in your navigation bar.

A2: Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_right. Value: key(87:com.android.systemui/2131231004). This is KEYCODE_MEDIA_NEXT and will show up as a right arrow in your navigation bar.

Next up, we’ll create the second Profile that triggers when the music app’s notification is dismissed. This Profile will get rid of the media control keys when the notification has been dismissed. Create a new Profile and name it “Disable Media Nav Keys.” Again create an Event Context and select the Notification Listener plugin. This time, for the Notification Event select Removed but again select the same music app you want monitored.

Again add a Task (without a name is fine) and create the following two actions:

These two actions will clear your navigation bar keys so the media playback control keys will no longer be there.

That’s it! Now when you start music playback, you’ll see additional keys on your navigation bar to control media, but when you dismiss your music player’s notification, these keys will disappear.

Download and Import

As with all Tasker related tutorials, we will be providing the XML files you can download and import. Download the prf.xml files from AndroidFileHost below and save them to your internal storage. Open up Tasker and long-press on the Profiles tab up top until you see an Import button. Tap on that and look for the XML files you just saved, then select them to import them (you’ll have to do this one by one). Make sure you have granted Notification Access to Notification Listener enabled and have granted the WRITE_SECURE_SETTINGS permission to SecureTask as mentioned in my article, otherwise these Profiles will not do anything on your phone!

If you’re wondering what else we can accomplish with SecureTask and Android O, stay tuned to the XDA Portal because we have a lot more to share. Expect more tutorials on how you can make your navigation bar in Android O accomplish many useful functions!

About Author

Long-time Android enthusiast starting from all the way back to the Sprint HTC Hero. Partial to the Nexus line, but open to try anything with Android on it. XDA's resident master of everything Tasker.
Please direct media inquiries to mishaal@xda-developers.com

Google Pixel XL - Google Edition (Unlocked)

Samsung Galaxy S8 (T-Mobile) [SM-G950U]

Samsung Galaxy Note 5 (Unlocked) [SM-N920I]

XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to make the most of their mobile devices, from customizing the look and feel to adding new functionality.Are you a developer?