PHONK – A Hacker’s Fun Shortcut To Android Programming

As the common myth goes, the average human utilizes only about 10% of the true potential their smartphone is capable of. Especially when it comes to electronics projects, it seems that we often overlook how we can integrate and take advantage of their functionality here. Maybe that’s not a big surprise though — while it isn’t rocket science, getting into mobile development certainly has its hurdles and requires a bit of commitment. [Victor Diaz] figured there had to be a better way, so he went on and created PHONK, the self-contained creative scripting toolbox for Android.

PHONK is installed like any other app, and allows rapid prototyping on your Android device via JavaScript by abstracting away and simplifying the heavily boilerplated, native Java parts. So instead of setting up an app from scratch with all the resources defining, UI design, activity and application lifecycle management — not to mention the Android development environment itself — PHONK takes care of all that behind the curtain and significantly reduces the amount of code required to achieve the task you’re actually interested in. In case you’re worrying now that you have to actually program on your phone, well, you can, which can definitely come in handy, but you don’t have to.

Once the app is opened, a web server is started, and connecting to it from any modern browser within the same WiFi network presents you the PHONK development environment with everything you need: editor, file browser, console, and API documentation. You can write your code in the browser, and pressing the run button will execute it straight on the device then. As everything is self-contained within the app itself, no additional software is required, and you can start right away by exploring the set of provided examples that showcase everything supported so far: sensor interaction, BLE server and client, communication protocols like MQTT or WebSockets, OpenStreetMap maps, and even integration with Pure Data and Processing. Attach a USB OTG cable and you can program your Arduino, have serial communication, or interface a IOIO board. You can even connect a MIDI controller.

This is really impressive work done by [Victor], and a lot of attention to detail went into the development. If you have an old Android phone collecting dust somewhere, this would be a great opportunity to revive it and build something with it. And as [Victor] writes on the project’s GitHub page, he’s always curious what people will come up with. If you’re thinking about building a mobile sensor lab, or want to learn more about the sensors inside your phone, have a look at the 36C3 talk about phyphox.

31 thoughts on “PHONK – A Hacker’s Fun Shortcut To Android Programming

  1. It looks awesome ! Even though I’m not a big fan of JS I can definitely see it used by newcomers or for quickly hacking something, especially since Google has the habit of constantly changing how Android development should be done and you have to re-learn everything every few months

  2. I like the look of this – seems quite well suited for an app I got halfway through before getting distracted a couple of months ago.
    Sure, JS isn’t most people’s first choice best but it’s a damn sight better than the utter abomination that is Java and XML.
    My app is pretty simple in theory, but getting it to the point that I did was BY FAR the most unenjoyable programming experience I’ve ever had and I’ve been programming for 20 years in over a dozen languages. Heck, I even enjoy dipping my toes into x86 on occasion.
    Seems you can’t find two Android code examples online written in the same framework or context. And don’t even get me started about the bloat and dependency hell.
    Definitely going to give PHONK a try. Nice one, Victor! And nice one, HaD / Sven!

    1. Hi Andrew,

      PHONK is an evolution of a project called Protocoder that I created (also open source) and I started in 2012. It was made public in 2013 in Github (https://github.com/Protocoder/Protocoder). Yeah, that long ago! :) I made it for my own prototyping needs and help my students but at some point I had to feed myself and family and earn money so I had no more time to work on it.

      PHONK comes from the same roots as Protocoder. I basically restarted it as a hobby project and I used the journey to teach myself web development, bit of design, prototyping, etc :)

      I’ve never used droidscript myself but I can assure you is not a re-implementation. Perhaps one of those coincidences in time? :)

      Cheers

      1. I really like how simple you were able to keep the api calls to speak to the hardware in js. Indeed the export to apk is only thing left to make this totally awesome. Or just some way to have it start a certain default script by choice on startup is already a great improvement.

        1. Ah damn, I forgot to mention the shortcut feature.

          On the phone, each script has the 3 dotted menu to their right, and in there is an “Add shortcut to desktop” entry. This will create an icon on the home screen, which will then run that specific script right away within PHONK.

          1. Yes we just discovered ourselves. And wanted to reply that is what we needed. The apk is nice for in future but this already covers 90% of usecases. Awesome it totally worked on my son’s tablet that we wrote a little script on that he’s now playing with by clicking on the icon on his homescreen. Great work!

    1. PHONK has LibPd built-in.
      You can create a Pure Data patch and load it with PHONK. The example located in Other Libraries -> LibPd does exactly that.

      I will try to make a video tutorial showcasing how to do it. I will add it as an issue in Github so I wont forget about it :)

    1. I haven’t tried the MIT one, but based on some tutorials, it seems to provide almost as extensive UI design options as native app development in Android Studio, so you can have a lot of freedom in the design itself, but also the complexity that comes with that. The app logic itself is drag and drop via graphical elements like in Scratch, so you don’t really need to know how to program at all – which seems like the target group they’re going for.

      PHONK in comparison keeps the UI design simple, so you don’t have all the flexibility, but don’t have to worry much about it either. You need to actually write code do program the logic, but it requires a lot less to write compared to native app development. I’d say PHONK targets those who generally know what they’re doing, but just not how to do it specifically in the Android environment / want to have a shortcut.

      If I compare it with microcontroller development: the MIT one is Scratch, PHONK is Arduino, and native Android development is bare-metal programming. So depending on your skill set and what you’re looking for, either one can be a pro or a con. If you get frustrated by writing code, you might enjoy the MIT one. If you get frustrated by clicking stuff around and rather just want to write the code and get things done quickly, PHONK is probably your better option.

  3. I’ve just been testing this and it works great! Love the fact you can create a desktop short cut. As others have mentioned would be nice to be able to create a true APK. Maybe it would be possible to create a website that provides this service? Upload the source and download the APK? However, thanks Victor for all the work that has gone into this and HaH for write up.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.