Automating things on Android with Tasker (I)
This is probably an article that is long overdue to me personally. I have been an Android user since 2011, started with my Nexus S that I bought for use in college. It seems to me, the app Tasker had been very famous in the Andorid community, especially among users who know how to program.
For those who have never heard of this app, this is a powerful app that allows you to automate almost anything that you can think of on the Android system.For me,It was not until August of last year when I bought the tasker app that I started to realize how powerful this app is. I am really not a big fan of its old school UI and design so I didn't start using it until this year. After uisng it for a while, I did come to realize that there is no other apps close to it, if I were to move to iOS, this is probably among one the apps that I will miss. In this article I will explain how I used takser to automate things for myself, it is some boring stuff, but it did become something that I'm using everyday.
What can you use it for?
I will list one of the most used Tasks/Profiles that I created and used in this app:
Turn off/on ADB when using certain apps.
This is one of the easy ones that I found very useful. It is not uncommon nowadays for some apps to require you to turn off your ADB (Android Debugging Bridge) settings when you are using them, which to me, is quite annoying. So naturally, I created a Tasker profile together with a task to automate this. The trick here is you need to have root access, otherwise you are pretty much out of luck for this particular example. To create such a task, assuming you already have proper root access, go to the TASKS page in the app and click on the add icon, choose a name you like, and then you can create your first task! Think of a task as the things you want Tasker to do for you. In this particular case, my goal is simple: turn off ADB if it was not already off, turn it on if it was off. This way we can have one task that a turns off the ADB when you turns on the app; when you turns the app off, ADB will be switch back to on.
It is clear that we will need a global variable that holds the status of the adb status, to do this add an action: click on the button add icon while you are in the "Task Edit" page, and filter based on Shell, you will see a "Run Shell" as a result. Click on it, and in the "Command" input, enter "settings get global adb_enabled" and in "Store Output In" input, choose a global variable name you would like to use to hold the status of the current ADB status, just remember that you need to use all caps for the name for tasker to know it is an global variable. Also remember to check the "Use Root" checkbox. After this step, things will be simple, just add the if and else condition like I mentioned before, set adb_enabled to 0 if it is 1 and set it to 1 if it is 0, and after that don't forget to set the global variable again.
TL;DR Here is the XML, that you can directly import to your Tasker if you don't want to create it yourself:
<TaskerData sr="" dvi="1" tv="5.2.bf">
To import, you need to save the above snippet to XML on your phone. In tasker app, click and hold the "TASKS" tab header, select import and choose the file
To run the task based on your predefined conditions, go to “PROFILES” tab, click on add button in the button, choose the application you want, and then, chose the task you imported and you are good to go! Now the app won't say you can't use it because you have ADB turned on, Tasker will turned adb off when you are using the app, and turn it on when you are not using it! :)