Tips and Tricks for Android Users
Posts tagged howto
Screenshot on a Rooted Device
Jul 20th
In addition to capturing a screenshot with a computer using the Android SDK there’s also a screenshot application (available on the market, called simple ‘screenshot’, I’m not sure how to find out the package name to create a market link for it. It only works on rooted devices, but all of mine are. One nice feature is the “shake to capture a screenshot” option. So that instead of having to keep hopping into the screenshot app to setup a shot, back to the app, wait, hop back to setup another time delayed shot, back to the app, etc. Just setup screenshot to capture when you shake and go through whatever set of screens you want.
Getting the Most Out of Froyo
Jul 14th
If you’ve got Froyo on your phone now and you’re looking to make sure you know about all the changes, check out this Android 2.2 review from AnandTech. It walks through all the differences compared to the 2.1 release, and there are a few good points in there. Everyone knows about the hotspot functionality for instance. But I had missed the automatic updates from the Marketplace till just now. Maybe there’s something in there you missed too.
Keeping Recovery Image After Reboot
Jul 11th
I’ve been trying lots of custom images on my N1 and G1 recently. One minor annoyance was that after installing a custom recovery image like Amon Ra to flash different base images I seemed to revert back to the default recovery image after a reboot. It wasn’t too annoying cause I kept the recovery.img on my sdcard and just did a flash_image before rebooting whenever I wanted to apply updates. But still, annoying.
Then I ran across this description of replacing the recovery partition, which explains that part of the boot process is writing the recovery.img from /system/recovery.img. That explains a lot! That page also describes how to replace the /system/recovery.img so that you keep your new recovery image after each boot. Ahh, now I have my full set of menu options whenever I hit recovery.
How To Unlock and Root a Nexus One
Jul 8th
I have a Nexus One that I’ve been fooling around with. It normally doesn’t have a SIM in it, I’m just using it to fool around with. So I’ve muddled my way through installing Froyo on it manually and taking it through a few updates. Generally I’ve been brute forcing my way through the processes based on following forum posting after forum posting.
Finally tonight I took some time to actually search around some and try to find “the right info” to get a rooted version of a custom firmware onto the device. The wiki area of the Cyanogenmod site is definitely the right place to go. They have some “Full Update Guides” linked from the front page which walk through step by step the different processes you need to go through, including a process for installing a Cyanogenmod firmware starting from a stock Nexus One. Exactly what I was looking for. It walks you through all the complementary processes too, like unlocking the bootloader and installing a recovery image.
I went with the stable Cyanogenmod release, so I’m slightly downgraded in terms of the Google release this bases off of. But there’s a bunch of capabilities in the new recovery image as well as root access to weigh that against… and right now root access is definitely winning.
Getting WebView To Load New Pages
Jun 3rd
There are a bunch of examples of using WebView to display HTML content loaded from the web in an Android app, including the sample from Google for the WebView class. However the ones I found generally don’t load new pages on their own. I can load up Google, but if you click on anything in the app it launches a browser and takes the user out of the app. The answer to the problem is in the additional points on that Hello, WebView page – you need to set a new WebViewClient to handle the URL load requests. Their example is very helpful, but I prefer to do the override with an anonymous inner class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.loadUrl("http://google.com");
setContentView(webview);
}
However, if you follow a link to an image it downloads instead of opens in the view. That’s the same thing the built in browser does, but wasn’t the behavior I expected. I’ll have to figure out how to handle that a bit better.
Compiling C Code for Android Using OS X
May 27th
I wanted to try out compiling some native C code for use on my device, but I wanted to do it using my OS X machine. I found this post about using the prebuilt toolchain over at Android Tricks, but figured I would write up some additional details for those who might also be looking.
- Follow the instructions to download and build Android from source. Follow the whole thing (I had to create a case-sensitive disk image and all), including the actual build step. Otherwise you won’t have the libraries necessary and agcc will error out when you try to run it.
- Add the prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin subdirectory of where ever you built the source to your PATH, add it to your .bash_profile if you want.
- Download the agcc wrapper script, put it somewhere in your path, and make it executable.
Now you should be ready to compile a program and download it to your phone. This was my test app:
#include <stdio.h>
int main( int argc, char **argv ) {
printf("Hello from Droid Hacks!\n");
return 0;
}
And you should be able to compile it with “agcc hello.c -o hello” and end up with a hello executable:
~ > agcc hello.c -o hello ~ > file hello hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped ~ >
And you can move the file across to the phone and run it. You’ll have to make a directory to push it into. The sdcard is marked as noexec, so you can’t run stuff from there. And the data directory has more restrictive permissions. So you’ll have to su and create a directory on the data partition, and relax the perms on that directory:
~ > adb shell $ su # mkdir /data/droidtest # chmod 777 /data/droidtest # exit $ exit ~ > adb push hello /data/droidtest 418 KB/s (6747 bytes in 0.015s) ~ > adb shell $ cd /data/droidtest $ ls -l -rwxrwxrwx shell shell 6747 2009-05-27 08:56 hello $ ./hello Hello from Droid Hacks! $
And of course you can run the same thing from the terminal on your device as well: