Android Scripting Environment

Google has recently released a scripting environment for Android that allows you to write Python, Lua, or BeanShell scripts that interface with Android functionality. From the project page:

  • Handle intents
  • Start activities
  • Make phone calls
  • Send text messages
  • Scan bar codes
  • Poll location and sensor data
  • Use text-to-speech

Tags: , , , , , ,

No Comments

Getting WebView To Load New Pages

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.

Tags: , , , , , , ,

No Comments

Monitoring Network Traffic Using OS X

Here’s a tip for monitoring network traffic from your Android phone using OS X. The same thing works for iPhone (or any other mobile device you can configure to use a wifi connection). I frequently use it to see how some bit of client/server interaction is done.

  • Install Wireshark
  • Follow the instructions in the readme to also install the ChmodBPF script
  • Under Sharing area of the OS X settings app configure your system to use an ethernet connection and share it out to wifi clients
  • Now configure your device to connect to the wifi network provided by your system, test to make sure it works
  • Startup Wireshark and set it to capture traffic (wifi is en1 on MacBook Pro systems, what I normally use)

And that’s it, you should now get quite readable dumps of what applications are doing to communicate. Lots of interesting things you can learn digging into how folks structure their client/server interaction.

Tags: , , , , , , ,

No Comments

Long Press on the Home Key

Intuitive to Nokia users, but I don’t think folks coming from other platforms have picked it up. If you press and hold the home key you get a list of recent apps, which makes switching around a lot easier if you’re bouncing back and forth. Here’s what the app list looks like when it comes up:

running_apps

Tags: , ,

1 Comment

Launcher Dock

Another widget I’m running now that I have Cupcake installed is “Launcher Dock”. It’s a 1×1 widget that holds launchers for up to 8 apps. I put some of my less frequently launched (but still relatively frequently used) apps in there so that I can have all their icons on the main screen.  This is a shot of my main screen with a configured Launcher Dock by the bottom right corner, just above the San Mateo weather widget:

launcher_dock_1When you tap the widget once it brings up a selector with launchers for each of the apps you’ve added plus an icon to start the widget configuration interface. Here’s what mine looks like after tapping on the widget:

launcher_dock_2And what the configuration interface looks like if you tap on that center icon:

launcher_dock_3I think it’s a pretty slick widget. Great way to increase launcher density if you have a few widgets taking up some space. And it looks pretty good there on the home screen.

Tags: , , , ,

2 Comments

Compiling C Code for Android Using OS X

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.

  1. 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.
  2. 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.
  3. 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:terminal_c_app_rotated

Tags: , , , , , , , , ,

2 Comments

Root Access Terminal Under Cupcake

I imaged my development phone with the Android 1.5 images from HTC. I was able to su to root when I connected to the phone using “adb shell”, but wasn’t able to get root when using the terminal app on the phone itself. There’s nothing that keeps you from setting up a mechanism to get root from the handset though. Just do this from an adb shell session after you su to root:

  • mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
  • cd /system/bin
  • cat sh > usu
  • chmod 4755 usu

Some of the instructions I found online suggested just calling the new binary su, but I was concerned about that overriding the default su depending on what path is getting used. So I just created a whole name “user su” which won’t reject the handset user when I try to change to root:

terminal_root_rotated

Tags: , , , ,

No Comments

Toggle Settings

Normally I have a few quick toggle applications sitting on my home screen to quickly switch on and off Bluetooth, Wifi, GPS, etc. It really saves a ton of battery life switching off hardware when it’s not in use. I just ran across the free Toggle Settings app from cooolmagic. It has all the hardware switches, some cool status info (like what wifi network you’re connected to), and new toggles for stuff like auto-sync. Very useful, and it looks pretty slick. Just search for “Toggle Settings” in the market and you should find both the 1.1 and 1.5 versions of the app. Here’s a quick rundown of the controls:

  • Turn on and off airline mode
  • Turn on and off autosync
  • Turn on and off bluetooth
  • Turn on and off GPS
  • Turn on and off Wifi, and show what network you’re connected to if you are connected
  • Control the brightness level and screen timeout, or disable screen timeout completely
  • Turn on and off silent mode
  • Control the volume

toggle_settings_1toggle_settings_2

Tags: , , , , , , , ,

No Comments