[A Juju adventure] Linking up with Android

In my previous entry, I argued that Ubuntu is possibly the best development environment to write connected android apps, thanks to Juju. Although using WordPress was possibly not a great example :) I still think that this idea has legs! Hence, I have decided to build an example project.

The example will mainly  be a simple and plan ToDo list app for Android, that gets its items from a back-end MySQL server.

So here is my list of things to get done for this example project:

  • Proof that you can access a Juju local environment from the Android Emulator
  • Develop a TODO list android app
  • Using a few charms from the charm store plus a custom one, set up a MySQL database that can be exposed through a web service with simple commands/steps
  • Connect the android app and the webservice, so they talk to each other.

And as there is no time like the present, here is the first bullet point!

Accessing a Juju Local Environment from the Android Emulator

As I was working on my wordpress charm, the easiest thing for me to do was to access the local webserver set-up for the blog.  I first installed the Android SDK, which turned out to be pretty easy to do by just following the instructions posted at http://developer.android.com/sdk/index.html . Apart of the sdk tools that download you the emulator, build tools and so on.. you can also choose to use Eclipse as your IDE. If you do this, you can then install an Android plug-in that is *very very* complete.  Having had previous experience with Eclipse, I choose this root and unless you feel very strongly against it, I recommend that you do the same.

Once I had the SDK installed, I run the 2.2 emulator (because that happens to be the version in the spare Android phone that I plan to use later on) and open the local IP address of the WordPress service.  That just worked fine.

Then I decided to create a sample android project and tried some code to do the same. I found that the following method within the main activity of the project was able to ping and then open in a browser window the wordpress app:

private String hostip = "192.168.122.137";

...

public void pingme(View view) {
 TextView info = (TextView) findViewById(R.id.mytext);
 WebView mweb = (WebView) findViewById(R.id.webView1);
 InetAddress in = null;

 Log.w("PING","trying to reach" + hostip);
 info.setText("trying to reach" + hostip);
 in = InetAddress.getByName(hostip);

 if (in.isReachable(5000)) {
   info.append("\nHost found");
   Log.w("FOUND",in.getCanonicalHostName());
 } else {
   info.append("\nHost found");
 }
 mweb.getSettings().setJavaScriptEnabled(true);
 mweb.loadUrl("http://"+hostip);
}

So in a nutshell, the first bullet point (and the easiest) of my list is completed!

About these ads

4 Responses to [A Juju adventure] Linking up with Android

  1. Pingback: [A Juju adventure] Linking up with Android | Victor Palau’s Blog « towerysdev2

  2. Pingback: [A Juju Adventure] Charming Lamp! « Victor Palau's Blog

  3. Pingback: [Juju Adventure] Android ToDo and Juju « Victor Palau's Blog

  4. Pingback: [Juju Adventure] Live testing « Victor Palau's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: