Friday, March 31, 2017

How to Add Forward/Backward Keys to Android O’s Nav Bar to Quickly Read Emails

If your time spent on your smartphone consists of going through a ton of e-mails, then you may find it annoying to accidentally switch messages when you're trying to see your entire e-mail message. Thanks to the new navigation bar customizer in Android O, we can add new keys to the navigation bar to perform custom actions. In this case, we'll be adding two new keys to the navigation bar that will move forward/backward in your e-mail list whenever we are using the Gmail app.

Thanks to Eli Irvin for (again) testing this out for me, and capturing the above screen recording.

If you've been following our previous Android O tutorials, then you'll know how we'll be tackling this problem. This tutorial is fairly similar to our picture-in-picture button tutorial, so if you've read through that then this one should be a breeze.


Add Forward/Backward Keys to Nav Bar while in Gmail

Requirements:

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 both applications, we need to set both of them up.

In order for Tasker to detect what application we're in, we need to grant its Accessibility Service. Doing so is very quick, simply go to Settings –> Accessibility and look for "Tasker" on the list of Services. Enable the Accessibility Service.

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 only a one-time thing, and we'll be using SecureTask in future Android O-related tutorials (of which there are a couple more), so it's definitely worth doing it.

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.

  adb shell pm grant com.balda.securetask android.permission.WRITE_SECURE_SETTINGS  

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 Profile

Open up Tasker and create a new Profile. Name it "Gmail Scroll Keys." Select the Application Context, and look for the e-mail app you want to enable the navigation bar keys in (eg. Gmail). Select the app(s) that you want, then back out to next create a Task.

Tasker will ask you to attach a Task to this new Profile. Create a new Task when asked, and name it (or don't). We will create two Actions in this Entry Task, as follows:

  1. A1: Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_left. Value: key(21:com.android.systemui/2131230907)
  2. A2: Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_right. Value: key(22:com.android.systemui/2131231004)

That's it for the Entry Task (the one that runs when you enter the e-mail app), now we need to add an Exit Task to disable the two keys when we leave the e-mail app. Create an Exit Task by long-pressing on the Entry Task and selecting the "add exit task" option when it pops-up. We will also create two Actions in this Task, as follows:

  1. A1: Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_left. Value: null
  2. A2: Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_right. Value: null

That's it! Now when you enter the Gmail app (or whatever other e-mail app you've chosen), you'll now see the two navigation bar keys to allow you to move forwards or backwards in your e-mail list.


Download and Import

As with all Tasker related tutorials, we will be providing the XML file you can download and import. Download the prf.xml file from AndroidFileHost below and save it 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 file you just saved, then select it to import it. Make sure you have Tasker's Accessibility Service enabled and have granted the WRITE_SECURE_SETTINGS to SecureTask as mentioned in my article, otherwise this Profile will not do anything on your phone!

Download the "Gmail Scroll Keys" Profile from AndroidFileHost

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



from xda-developers http://ift.tt/2ohc04v
via IFTTT

No comments:

Post a Comment