[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!

5 thoughts on “[A Juju adventure] Linking up with Android

  1. Hello,

    I was going through your blog series for android application using juju.
    I have to do something similar for my project.
    So, just wanted to ask if juju is running on openstack. If yes, then how did you accomplish it. Did you used the MAAS -juju approach to deploy openstack or did you deploy juju over the private openstack cloud. This query is a bit off the blog series but I am trying to deploy juju over my openstack cloud, and then planning to use the mysql services on juju for the android application.
    but I am unable to bootstrap juju over openstack due to a ssh issue. The juju instance that gets created at the time of bootstrap gets a public floating IP but it times out every time as the IP is denied ssh access. It throws up Connection refused error, permission denied (Public key).

    Any help would be highly appreciated.

    Thanks
    Sai

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 )

Facebook photo

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

Connecting to %s