I cheated YouTube to stop sucking my battery.
I developed an android application because I needed this feature for myself and it wasn't available. I published it on Play Store, so that I could make the most out of my efforts. Today, I’ll be sharing this easy-said-than-done experience with you.
App development wasn’t much of a passion for me but this was the path I had to follow. In my university days I was experimenting with different algorithms relating to artificial intelligence, computer vision, deep learning and all sorts. What I didn’t like was to work in the lab. I would prefer my own room with no limits to the mess I can make, have food and lie down whenever I need a break.
The downside to that was I could never get access to the expensive lab equipment like cameras, sensors or robots. I certainly didn't have money to buy all this. Nevertheless, I knew that my phone had a camera, Wifi, accelerometer, gyro meter, NFC, storage, touch interface etc. I decided to use them for all my experimentation, thus getting into android development. And it was amazing, everything I wanted to access in my phone was just a couple of lines of code away. This way I could focus more on the algorithms than wrestling with cumbersome interfacing of hardware.
However, commercial app development was a whole other game. You need to think more in terms of graphics and aesthetics, rather algorithms. I had to swim this sea, when I decided to dive into the entrepreneurship ocean. But still I found myself more focused on the underlying bases on which the project was running. So, after 4 years of experience I still don’t like to call myself an app developer. I just had to do it.
I lived in Pakistan at the time, where Internet services are still prone skepticism and mistrust. We don’t get to enjoy services like Google Play Music or Spotify. Some paid services are available but the USD-PKR currency ratio just makes it a bit expensive for us. So, the one good source of such services was YouTube. I used to listen to music here and follow video casts like The Great War and Comics Explained. It was really nice to see all this available content.
However, we all know one pain that YouTube gives us… unable to play in background. Yeah, I know right!
This was a huge battery sucker for my phone and it was annoying that I was spending too much power on the videos that I wasn't even seeing but only listening. Well I decided to do something about it.
I thought the problem was unnecessary screen on time, right? Then, how about I create an application that could turn off the screen at will and turn on at will. That way the YouTube app would think that neither I have locked the phone nor have I switched the application. Only the power to the screen is cut off!
It was a time when android had released its Nougat flavor and with it the feature of quick setting tiles was introduced. For those who don’t know, a quick settings app is one that can be triggered through your notification drawer. Similar to your wifi button. So this is what I set out to do:
You click a button in the drawer and your screen goes black. The screen turns back on when you touch your screen again. I decided to call it Lights Out.
This seemed plausible and it was perfect since I already had understanding of android development tools, until a slight miscalculation came into play.
I had android studio installed, I updated the SDK packages to work in Nougat. Then I found this simple tutorial by learn2crack for creating a quick settings application. It seemed smooth till this point but it became complicated when I got into the screen off feature.
The problem was that android doesn't allow apps to turn off screens. Yes! Apparently it was a security feature so that apps couldn't turn off phones. Bummer right?
Nevertheless, I wasn't about to give in. I figured out another feature that switched off the screen. It’s when you use calls. You see whenever you put your phone against your cheek its screen goes black to preserve battery and prevent unnecessary button clicks. The way it works is that there is a proximity sensor near the top speaker of your phone. When you block that sensor with a ridged body it turns off the screen.
Now, it dawned on me that while listening to music my phone is either in my pocket or on a surface. It was perfect, if I could just tap into that feature it should work.
Fortunately, android provides these APIs that allows you to use this feature and voila! It worked!
This is the part I hate the most. For myself I could use a crappy looking application but for commercial purposes it was a necessary evil. Anyways I wasn't aiming for anything fancy so I kept it simple and straightforward (KISS, as I like to call it).
First, I needed was a logo. I used the android studio built in logo generator to create a backdrop design. Then I downloaded a PNG icon from freepick. The result looked something as follows. This also became the icon for quick settings drawer.
Second, came the app interface. This is was essentially going to be a single page with a tutorial of how to use the application. I used this awesome guide by Design+Sketch and implemented it. It looked pretty nice at the end.
Publish and Promote:
I already had an android developer account which costs like $25. Uploading the app wasn’t a problem but the promotional material was.
That was it, no team required, nothing fancy to do. Just a simple application that I wanted for myself and wasn't available on Play Store. Now, I listen to YouTube content without worrying about the battery or accidentally switching apps. With headphone on, my phone stays in my pocket and the proximity sensor does it’s trick. I don’t intend to make money out of this..
It just reminds me that when there is a will there is a way.