Archive for Android

RemoteDroid has been open sourced

I’ve finally gotten around to open-sourcing RemoteDroid, and putting it up on Google code. You can get to it at:

http://code.google.com/p/remotedroid/

You’ll also always be able to find the latest .apk and server files there.

Part of my reason for open-sourcing it is that I’m just one person, with just one phone. Like or not, Android has already fragmented, and will probably fragment even more in the future, so support for every Android device out there will become increasingly difficult. That’s where open-source comes in.

I’m looking for contributors to help debug on platforms other than the G1. There are several issues that I simply can’t fix because I have no way of replicating them. Additionally, other people might think of features that I haven’t or haven’t had time to implement. If nothing else, people might be curious about how RemoteDroid works, and open-source is a great way of dealing with these issues.

If you’d like to help, feel free to email me at admin@remotedroid.net, or use the feedback form.

Comments off

Android browser caching

I just wanted to get this out there, Android’s browser caches like a madman. It completely ignores POST variables. This is particularly relevant when doing AJAX calls. You can’t simply add a timestamp to POST and expect the Android browser to give you new page data. You have to append to timestamp to the GET query string.

Pragma: no-cache, and all the other server-side headers also have no effect as far as I can tell.

It makes sense though. Since the browser’s on a mobile network, and since they want to minimize network traffic as much as possible, caching is going to be extremely aggressive.

Comments off

Maintaining an object through an orientation change

One of the head-scrathers about Android for me has been that when you open the keyboard on a device with a slide-out keyboard, the current activity is totally destroyed, then rebuilt again. I understand why it’s done, since all of a sudden, you’ve got a new resolution, and a new set of capabilities, but I never knew how to differentiate an orientation change from an Activity being destroyed because you’re going to a new Activity.

An example of this might be if you have a game thread, or some process going that you don’t want to have to shut down and restart just because you suddenly have to deal with a keyboard. The solution to this is Activity’s onRetainNonConfigurationInstance() method, as described here:

http://android-developers.blogspot.com/2009/02/faster-screen-orientation-change.html

Now you know!

Comments off

Quick alert, or non-modal dialog in Android

It’s called a Toast.

Here’s a quick little tutorial on how to use it.
quick alert tutorial

Comments off

My essential Android apps

A quick list of 3rd party apps that really make the Android experience for me:

OI File Manager

There are several good file browsers out there, but I like the philosophy behind this one. I prefer the directories and folders metaphor over the idea of every app keeping it’s own list of files, a la iTunes, or the iPhone’s big list o’ apps home screen. This means access to the filesystem. At the moment, there isn’t a native file picker widget/view/whatever, so OpenIntents designed their file browser to provide that.

With that in mind, the next app is

Download Crutch

This just allows the Android browser to download any file type. Currently, it only downloads files that have corresponding apps. This is by design. Since Android doesn’t have a native file browser, if you were to download something without an app to manage it, you’d never be able to delete it. People will make new apps, and those apps will be able to deal with different files, therefore they need a way to tell the browser what the new file types are. I guess Download Crutch just tells the browser that it’ll handle everything.

Terminal Emulator

Because every computer needs a command line.

Connectbot

An SSH program for Android. If you have a Linux box running somewhere, you can just SSH into it, then use IRC, or any command line program you want. I think you can even use SSH tunneling, but I’m not sure.

Tetherbot

It takes some configuring, and it’s really only good for browsing the web, but when I happen to have my laptop with me, and there’s no wifi available, this app is indispensable. T-Mobile isn’t keen on tethering, so this app can’t be released on the market, but lucky for us, Google lets us install whatever the heck we want on our phones. Eventually, Google will allow us to write native apps, and we’ll hopefully start to see true tethering apps, (You can already do this if you’ve rooted your phone) but until then, this app works pretty well.

So basically, what I really want is a very small computer that also happens to be able to make phone calls. Netbooks won’t fit in my pocket, and don’t serve as phones. The iPhone’s soft keyboard bugs me, I don’t like it’s overly managed interface, and the fact that it’s completely tied to iTunes. Windows Mobile just blows, and Palm is somewhat outdated, so we’re left with Android.

At it’s heart, a mobile phone is just a computer, and computers at their heart, are supposed to be able to do just about anything that you can figure out how to tell them to do. These apps aren’t everyday use programs, but they go a long way towards providing the kind of flexibility that you should have out of these devices.

Comments off

Running native code in Android 2

So, the previous method only really works for statically compiled programs, meaning it’s kinda useless for anything more complex, or for cross-compiling much of anything really.

Luckily, I found another page that details a better, though more time consuming way of doing things.

Compiling for Android

Basically, you’re downloading the Android source and compiling it to get a cross-compiler that links to the appropriate Android libraries, and anything else you might need.

CAVEATS:

  1. Compiling takes a VERY long time. Don’t start the compilation over SSH, because something bad will happen, and you’ll be forced to close the SSH session, which’ll bork everything. If you’re doing stuff remotely, VNC into your Linux box, open a terminal window there, and do what you need that way.
  2. I haven’t tested this on anything other than Linux.

Comments off

Running native code in Android

As everyone probably knows by now, Doom has been ported to Android.

This is exciting for two reasons,

  1. It’s Doom!
  2. It’s actually native code running with a Dalvik frontend.

Now, Dalvik doesn’t have JNI, so how can you write something in C and run it?

This guy will lead you down a link-clicking rabbit hole that’ll tell you how. The important parts are the compiler (Choose ARM GNU/Linux and IA32 GNU/Linux), and the technique of running system commands from Dalvik, which is detailed on Gimite’s page.

One note, he links to a dynamic link method of getting everything to work, which doesn’t seem to be strictly necessary. I just compiled this:

#include <stdio.h>

int main (int argc, char** argv) {
        printf("Hello world!\n");
        return 0;
}

and it wrote to stdio just fine.

The other important part is getting the native code to actually run. You can put your binaries in your assets directory, but I’m thinking that the directory is within the .apk your app gets bundled into, and I don’t think can even run anything from there. I wound up copying the binaries from the assets directory to /data/data/com.joshsera (where com.joshsera is replaced by your package name), chmodding it, and running it.

File newHello = new File("/data/data/com.joshsera/hello");
try {
        newHello.createNewFile();
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(newHello));
        BufferedInputStream in = new BufferedInputStream(this.getAssets().open("hello"));
        int b;
        while ((b = in.read()) != -1) {
                out.write(b);
        }
        //
        out.flush();
        out.close();
        in.close();
        // chmod?
        this.doCommand("/system/bin/chmod", "777", "/data/data/com.joshsera/hello");
} catch (IOException ex) {

}

doCommand is where I stuck the code to run system commands.

public void doCommand(String command, String arg0, String arg1) {
        try {
                // android.os.Exec is not included in android.jar so we need to use reflection.
                Class

Related Links

Resource Links