How to Automatically Change your Keyboard on a Per-App Basis

How to Automatically Change your Keyboard on a Per-App Basis

Unlike iOS, Android has had the ability to change your default keyboard for many, many years. A huge number of alternative keyboards have proliferated on the Google Play Store as such. Although most people probably use one of either Gboard, Swiftkey, or Swype, there are a lot of other great keyboard applications that millions use daily, for a number of reasons. One reason that many people seek non-default keyboard applications is because of language support.

Some keyboard apps are better built for certain languages, but generally aren’t the best in all other regards. A lot of multi-lingual users find themselves frequently switching between keyboard apps whenever they want to type something in their native language versus wanting to type something in English. If you have multiple keyboards enabled on your device, then the method you can use to switch between keyboards depends on what device you have. Samsung smartphones, except for the newly released Galaxy S8 or Galaxy S8+, post a notification when the keyboard is shown that, when tapped, opens up the keyboard switcher dialog. Other phones with virtual navigation bar keys, such as those by Huawei, show a button to switch the keyboard in the nav bar itself.

If you find yourself frequently switching keyboards only when you’re using certain applications, here’s a tutorial on how you can do automatically so on a per-app basis. This way, you can forego using the nav bar button or the notification to switch keyboards, and instead automate this process. Although my previous statements mention this being most useful for multi-lingual users, I can think of a few other occasions where this might be useful:

  • Automatically switch to Google voice typing when you’re using Android Auto
  • Automatically switch to your password manager’s keyboard when you’re ready to input a password

Automatically Switch Keyboards on Per-App Basis

Requirements:

OR

We’re going to be using Tasker to detect what application we’re in, and then either SecureTask or AutoTools to automatically switch our keyboard. SecureTask and AutoTools are both Tasker plugins that can do what we’re looking for, however, in this case AutoTools is much more user friendly in setting this up. Because AutoTools is not a free plugin, I will mention how you can do this using SecureTask, but just know that it will require a bit of extra effort on your part to get it up and running.

Step 1: Enabling Tasker’s Accessibility Service

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.

Step 2: Setting up SecureTask or AutoTools

Next, we need to grant SecureTask or AutoTools the ability to modify system settings on our device. In order to do so, we have to grant SecureTask or AutoTools 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, so once you do this you can use the plugin to follow many of our other tutorials that use this plugin (of which there are many).

If you already have ADB set up, you can skip Step 2A.

Step 2A: 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.

Step 2B: Granting WRITE_SECURE_SETTINGS to SecureTask or AutoTools

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

If you’re using AutoTools, then enter this command:

adb shell pm grant com.joaomgcd.autotools android.permission.WRITE_SECURE_SETTINGS

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

Step 3: Setting up the Tasker Profile

Open up Tasker and tap on the + button to create a new Profile. Tap on Application to add an Application Context. In the App Selection screen, choose the app(s) that you want the keyboard to be automatically switched in.

Press the back key or tap the back arrow on the top left to back to Tasker’s main screen. Tasker will ask you to create a new Task or attach an existing one. Choose to create a new Task. Don’t bother naming it, just tap on the checkmark to go to the Task editing screen.

Now we will create the Task. Follow Step 3A if you are using AutoTools, or skip to Step 3B if using SecureTask.

Step 3A: Tasker Task if using AutoTools

Once you’re in the Task editing screen, follow these steps to create the entry Task which will change our keyboard when we enter the app(s) that we chose before):

  1. Add a new Action by tapping on the + icon in the bottom middle.
  2. Press Plugin then AutoTools then Secure Settings.
  3. Tap on the pencil icon to bring up AutoTools configuration.
  4. Scroll down and tap on Services.
  5. Select Input Method.
  6. Choose the keyboard app that you want to automatically switch to when you open your app(s) of choice).
  7. Press the back key then tap on the checkmark to save AutoTools configuration. Back in Tasker’s screen you should see the name of the keyboard service next to “Input Method:”
  8. Press the back key or tap the back arrows twice to finish creating this Task.

Next, we need to create an exit Task that triggers when we leave the app(s) that we chose. This will restore our keyboard back to our favorite/default keyboard. Here are the steps:

  1. Back in Tasker’s main screen, long-press on the existing Task that you just made. A pop-up will show up with some options. Pick Add Exit Task.
  2. Opt to create a new Task here.
  3. Once you’re in the Task editing screen, repeat steps 2-8 from the previous instructions, except during step #5 select the keyboard that you want to revert to once you leave the app(s) that you picked.

Step 3B: Tasker Task if using SecureTask

Once you’re in the Task editing screen, follow these steps to create the entry Task which will change our keyboard when we enter the app(s) that we chose before):

  1. Create an Action by pressing the + button in the bottom middle.
  2. Tap Plugin then SecureTask then Secure settings.
  3. Tap the pencil icon to open SecureTask configuration.
  4. In SecureTask, set the Action to Read. For the Setting type secure default_input_method. For the result variable name type keyboard.
  5. Tap the checkmark to save SecureTask configuration then tap the back key or press the top left arrow key to return to the Task editing screen.
  6. Add another Action but this time go to Variables then Variable Set.
  7. For the Name set it to a global variable that indicates the name of the current default keyboard. Tasker recognizes global variables when the first letter of the variable name is capitalized. For instance, I put the Name as %Gboard.
  8. For the To set it to %keyboard.
  9. Press back to return to the Task editing screen.
  10. At the bottom left of the screen, tap on the play button to run the Task.

Steps 2-10 are designed to save the keyboard’s service name is a global variable that we can reference when we need to change the keyboard. We need to know the exact name of the keyboard service, otherwise we can’t change to that keyboard. You can switch to the Variables tab in Tasker to see the name of the keyboard service that was just saved.

You will need to repeat steps 2-10 to save the keyboard service names for all your other keyboards that you want to switch between. All you have to do is manually change to another keyboard and repeat steps 2-10, however, you need to change the variable name in step 7. For instance, I changed my keyboard to the Xperia keyboard so instead of saving a global variable called %Gboard I named this one %Xperia.

Once you’ve repeated the above steps for the keyboards you want to switch between, we can now set up our actual Task to change the keyboard. Follow these steps:

  1. Delete the previous two Actions that we made by long-press selecting them, and then dragging the highlighted Actions into the trash can at the bottom.
  2. Add a new Action and go to Plugin –> SecureTask –> Secure settings.
  3. Tap on the pencil icon to open SecureTask configuration.
  4. For the Action this time choose Write. For the Setting again it will be secure default_input_method. But this time for the new value set it the global variable name of the keyboard you want to automatically switch to. For instance, I put %Gboard here.
  5. Exit the Task editing screen back to Tasker’s main menu.

Now we need to add an Exit Task that will trigger when we leave our app(s) of choice so Tasker will revert us back to our default keyboard of choice. Here’s the steps:

  1. Long-press on the Task we just created until you see a pop-up.
  2. Choose Add Exit Task.
  3. Create a new Task.
  4. Add an Action by going to Plugin –> SecureTask –> Secure settings. Action: Write. Setting: secure default_input_method. New value: global variable name of the keyboard you want to revert to after leaving the app.

Conclusion

Whether or not you use AutoTools or SecureTask doesn’t matter here – the end result is the same. When you enter the app(s) that you have chosen, Tasker will automatically switch your keyboard for you, and revert the keyboard change when you leave those app(s).

Once you’ve set these up, you can play around with when or where you want to use different keyboards. As I mentioned in the beginning, you can for instance automatically enable Google voice typing while in Android Auto. Or for instance if you’re using KeePass2Android, you can have Tasker switch to the KeePass keyboard when the KeePass notification is posted (note: this requires you to use another plugin such as AutoNotification or Notification Listener, which we won’t go into here for brevity).

We hope you found this tutorial useful. Keep an eye out on our tutorials category to find many more useful tutorials such as this one!

Discuss This Story

Want more posts like this delivered to your inbox? Enter your email to be subscribed to our newsletter.

READ THIS NEXT