My job requires me to install APK, launch application, test application, and uninstall application. Wrote this script to automate commands I have to run in console.
#!/usr/bin/php
<?php
$usage = <<<EOD
Usage example:
apker install /path/to/game.apk
apker launch /path/to/game.apk
apker uninstall /path/to/game.apk
apker /path/to/game.apk
EOD;
if (count($argv) == 2) {
installAPK($argv[1]);
launchAPK($argv[1]);
exit(0);
}
if (count($argv) == 3) {
if (strtolower($argv[1]) == 'install') {
installAPK($argv[2]);
exit(0);
}
elseif (strtolower($argv[1]) == 'launch') {
launchAPK($argv[2]);
exit(0);
}
elseif (strtolower($argv[1]) == 'uninstall') {
uninstallAPK($argv[2]);
exit(0);
}
else {
echo "$usage\n";
exit(1);
}
}
echo "$usage\n";
exit(1);
function installAPK($apk) {
echo "Install ...\n";
if (shell_exec("adb install $apk")) {
echo "Install successful...\n";
}
else {
echo "Install unsuccessful...\n";
exit(1);
}
}
function uninstallAPK($apk) {
$package = getPackage($apk);
echo "Uninstall $package...\n";
if (shell_exec("adb uninstall $package")) {
echo "Uninstall successful...\n";
}
else {
echo "Uninstall unsuccessful...\n";
exit(1);
}
}
function launchAPK($apk) {
$activity = getLaunchableActivity($apk);
$package = getPackage($apk);
echo "Launching $activity...\n";
if (shell_exec("adb shell am start -c android.intent.category.LAUNCHER -n $package/$activity")) {
echo "Launch successful...\n";
}
else {
echo "Launch unsuccessful...\n";
exit(1);
}
}
function getPackage($apk) {
$output = shell_exec("aapt d badging $apk");
// package: name='com.spoof.sms'
preg_match("/package: name='([^']+)'/", $output, $matches);
return $matches[1];
}
function getLaunchableActivity($apk) {
$output = shell_exec("aapt d badging $apk");
// launchable-activity: name='com.spoof.sms.com.home'
preg_match("/launchable-activity: name='([^']+)'/", $output, $matches);
return $matches[1];
}
?>
Posted in
Tao Of Programming at April 19th, 2012.
No Comments.
Linux kernel is capable of recognizing many Android devices connected through USB. You can make the device available in userspace through udev. In order to do that, I need to write some udev rules. I use lsusb to find the vendor ID needed to write udev rules. This is my udev rule (/etc/udev/rules.d/90-android.rules):
# Nexus One
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"
SUBSYSTEM=="usb",ATTR{idVendor}=="18d1",SYMLINK+="android_adb"
SUBSYSTEM=="usb",ATTR{idVendor}=="18d1",SYMLINK+="android_fastboot"
# HTC
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
SUBSYSTEM=="usb",ATTR{idVendor}=="0bb4",SYMLINK+="android_adb"
SUBSYSTEM=="usb",ATTR{idVendor}=="0bb4",SYMLINK+="android_fastboot"
Posted in
Blog at February 14th, 2011.
No Comments.
2 weeks ago I conducted an Android Training Workshop for CodeAndroid Singapore meetup at Google office. I have designed a tutorial to teach newbies the basic concepts of Android development. In this tutorial, developers learn the basics of Activity, View, Intent, and HTTP request. Developers were taught to create an application called QRTalk.
QRTalk allows user to type in some text message. It uses Google Chart API to encode this message and generate a QR code image. This image is then displayed in a WebView.
URL imageURL = new URL("http://chart.apis.google.com/chart?cht=qr&chs=350x350&chl=hello+world");
Bitmap qrBitmap = BitmapFactory.decodeStream(imageURL.openStream());
imageView.setImageBitmap(qrBitmap);
This is what I have learned while developing the tutorial. With 1 line of code, I am able to make a HTTP request and turn the HTTP response into a Bitmap object instance.
Lesson learned:
- Use more images in slides. Too much words on slides make it hard for people to absorb, and makes the presentation very dry.
- Cannot assume audience knows what is QR code.
Links
Posted in
Tao Of Programming at February 11th, 2011.
No Comments.
Sometime I am given an APK without the application source code. I need to gather information from the APK file. These information includes package name, version code, services, icon, permissions. Eventually I found out that this is what Android Asset Packing Tool (aapt) does. It is used by Eclipse to package your Android project into an APK package. Read more…
Posted in
Blog at October 11th, 2010.
No Comments.
I have published my first Android application. It is a simple application, which calculates the toll fare for travelling on Malaysia North South Expressway. Friends at CodeAndrod Malaysia have been encouraging me to publish an application. I was the first to start Android development, but the last one to publish app
One thing I learn from Nazrul, “Be proud of your work. No matter how small your project is, be proud of it and let the world know. If there’s a problem, the world will let you know too”.
It was my first time driving from Johor Bahru to Malacca. I wanted to top-up my Touch’n Go card but I did not know how much it cost to travel from Kempas to Ayer Keroh. I think it would be great to have an application that calculates the toll fare for drivers. That is why I developed this application. I am hosting the source code on Google Code.

Posted in
Blog at July 20th, 2010.
1 Comment.