Saturday, April 8, 2017

Add a Menu and Forward Button to the Nav Bar in Android O for Enhanced Web Browsing

Android O’s navigation bar customizer can be used for a myriad of cases, but it’s especially useful when you are changing the navigation keys contextually. In our tutorials, we are focusing on finding situations where adding new nav bar keys can enhance your app experience, and today we’ll show you how to add a menu and a forward button to the nav bar when using Google Chrome. These buttons will greatly enhance your web browsing experience, because it beats having to reach all the way to the top right to tap the menu overflow button.

Thanks to Eli Irvin for being my guinea pig and getting this screen capture.

As you can see above, two new nav bar keys are added to the navigation bar, but only while using Google Chrome. The left key opens Chrome’s menu (using KEYCODE_MENU) while the right key will trigger the “forward” function (using KEYCODE_FORWARD) in the browser. Unlike some of our previous tutorials, we aren’t utilizing any custom icons in the nav bar, so you won’t have to go and download anything extra apart from the required apps below.

We’ll show you how to replicate this setup on your own device so you can learn how to make your own custom nav bar configurations, but we’ll also provide a download link at the end of the article if you would rather skip to that.

Note: this tutorial is incompatible with our previous tutorial on adding scroll keys to the nav bar when using Chrome. You can pick either that Profile to use or this one depending on your preference, but not both.


Adding Menu/Forward Buttons to the Nav Bar while using Chrome

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 you’ll need SecureTask if you want to follow along any of my other contextual Android O-related nav bar tutorials (of which there are many), 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 press + to create a new Profile and name it something like “Toggle Chrome Extra Keys”. Select the Application Context. Scroll the list and select your browser app (in my case, I selected Chrome).

After you add your app and back out to Tasker’s main screen, Tasker will ask you to attach an existing Task or create a new one. Create a new Task but don’t bother giving it a name. Once you’re in the Task editing screen, add the following two Actions:

  1. Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_left. Value: key(82:com.android.systemui/2131230913)
  2. Plugin –> SecureTask –> Secure Settings. Action: Write. Setting: secure sysui_nav_bar_right. Value: key(125:com.android.systemui/2131231004)

Once that’s done, you can exit back to Tasker’s main menu. We will now finish out this Profile by adding an Exit Task to it, which will trigger when you leave the Chrome app. This Exit Task will clear the nav bar of these icons.

Add an Exit Task by long-pressing on the existing Task that you just added to the Profile. Tap on “add exit task.” Create a new Task, and then add the following two Actions:

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

Exit back to Tasker’s main menu, and you’re done. Tasker will now display the menu and forward keys while using Chrome, and clear them when not using Chrome.


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 “Toggle Chrome Extra Keys” Profile from AndroidFileHost

If you’re wondering what other useful keys we can add to the navigation bar more useful in Android O, check out our other tutorials!

HostGator Web Hosting

0 comments:

Post a Comment