How I Automated Booking OLA CABS
Alternate Title: Practically Learn Android Accessibility Services
My Daily Routine
I travel every day to work via either the metro or the local train. To reach the station, I need some last-mile connectivity. I use OLA cabs for this. Booking a ride on Ola cabs is really easy. Select the pickup and the drop location — and book a ride! But doing this on an everyday basis could be really tiring and monotonous. I used to wish for a ‘favorite routes’ feature in the Ola app. I decided to do something about it.
Need For Automation
What I really needed was automation. My expectations were to do the following tasks automatically:
- Open Ola app
- Select the pickup location
- Select the drop location
- Select the preferred ride
- Press Book Now and confirm the booking!
After some thought, I realized that I don’t want the last step. Because sometimes due to surge pricing, the cost of the ride becomes unpredictable (read: a lot higher). The old-school technique of negotiation with the cabbies directly is cheaper at such times. So, the app will open up, select the pickup and drop locations, and show me the prices for the rides. It will let the final decision be mine if I would like to book a ride or not. The real question was: how could I do this automation in Android?
Android Accessibility Services To The Rescue!
Android’s accessibility services make it easier to use an Android phone for those with disabilities. In addition to the services that are built-in in Android, developers can tap into the accessibility services with their own apps to create new features that can take advantage of them. The accessibility services run in the background. They receive callbacks by the system when accessibility events are fired. These events denote some state transitions in the user interface. These services can request the capability of querying the content of the active window. This can also help in interacting with a 3rd party app — in our case — Ola.
We will design an app that starts an accessibility service. This service will open the Ola app. It will also select the pickup and the drop location. Then it will automatically turn itself off to save battery. This way, we will automate booking a ride in the Ola app.
Disclaimer: Google states that applications using Accessibility Services should only make use of the system if they’re directly benefiting those that have disabilities. Even though the current use-case can be helpful for someone with a disability, it is not directly benefiting the disabled. You can create this app for yourself, but if you publish the app to the Play Store, chances are that your app will get rejected.
Show Me The Code
We need a code to do the following:
- Open ola app:
- Select the pickup and drop locations, and automatically disable the service as its work is done:
- We will create a new accessibility service called
FromHomeAccessibilityService
and make use of the above methods:
- We will register the service in
AndroidManifest
:
- The app has no UI. Users need to just turn on the accessibility service from the Android Settings, and the accessibility service defined above will do the rest. Hence the Android Settings for the accessibility should open directly when the user opens the app. Our
MainActivity
:
- The extra files such as
activity_main
layout,Helpers
class,strings.xml
, andaccessibility_service_config.xml
are hosted here:
- We will also be using the
AirBgTaskProjectNew
library to do tasks in the background thread. The usage and how to import it in a project is mentioned in the official library page:
That’s all!
The Final Product: Video
Conclusion — Build Your Own!
My everyday commute has certainly become better because of this. There are many advantages to this automation:
- It is the quickest way to open the app and select pickup and drop locations
- No chance of mistakes in the selection of pickup and drop
- Saves human energy, which was earlier getting wasted in this mundane task. Okay, I’ll admit it, I’m too lazy to do this low-level work every day.
I recommend you automate apps in your life too using the power of Android. If you could think of a use case in which we can help the disabled, reach out to me, and we will develop an app and publish it!
Lastly, a note about disability. When we are thinking about Android accessibility, lets not just think about permanent disability. Because say when we fracture our hand, aren’t we temporarily disabled as well? This way, it will help us think from the differently-abled perspective better.
Please clap for the article if you feel you’ve learned something new today!
Reach out to me: