Why Android is cool

These days I’m bumping in to a LOT of people using iPhones and loving them. The most happy iPhone users are the ones who have jailbroken their phones and now are able to stream live video recording and to access stuff that was locked down on their phone to begin with.

One of the things that they still envy Android users for is the high degree of pluggability that allows Android developers access to phone services such as the ability to react to an incoming call on the phone.

LookupIncomingCall is an Android application that uses this feature to look up names for any incoming call on the yellow pages of some countries.
When a new call is received the application simply does a lookup on a national yellow pages service and returns the name of the caller if found.
This is a very handy application to add to your phone and in the current version (1.6) it supports a number of yellow page listings in the US, Sweden, Germany and Denmark.

stacks_image_22_1

As you can see in the screenshot above, the LookupIncomingCall application looks up the number on a phone listing service and the name found is displayed in the notification bar at the top.

LookupIncomingCall supports a number of yellow page services, but the developer has been so kind to allow custom services to be added to the list as well.
This allows developers to plug in custom services for looking up numbers that are not known on public yellow page listings, such as internal phone numbers in a company.

I decided to put together a small program to look up internal phone numbers in my company.
My company uses 3 digit numbers when colleagues need to call each other, so my boss can be reached on the number 200 for instance.

I wrote some code that takes the phone number as input parameter and simply determines the length of the number to decide whether it’s internal or external.
The code below is deployed on Google App Engine at this location http://lookuplocalnumbers.appspot.com/ and the servlet containing this is mapped to the URL /number – not very imaginative, but hey it’s easy to remember :-)

The service can be called like this http://lookuplocalnumbers.appspot.com/number?number=73720000
returning the name of my favourite local pizza guy !

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String number = request.getParameter("number");
        String name = "Not listed";

        //local number ?
        if (number.length() == 3) {
            if (number.equals("200")) {
                name = "The big boss";
            } else if (number.equals("214")) {
                name = "The REAL boss";
            }
            //and so on.....

        } else {
            if (number.length() > 3) {
                name = call118(number);
            }
        }

        ServletOutputStream out = response.getOutputStream();
        out.println(name);

    }

The code above contains a very short lookup list of two persons – one is my boss, and the number 214 is my dear colleague who is responsible for my monthly paycheck, thus – The REAL boss :-)

If the number given is longer than 3 digits the lookup is redirected to 118.dk, a Danish yellow page service and finally the results are simply printed out, which makes the LookupIncomingCall application display the results in the notification bar.

Simple, fast and useful
So the above application is not very useful before you can tap into the complete phone directory of your company – the next person you definitely want in that directory, is the accountant who always calls you at the end of the month to complain about missing bills for your expense report :-)

But, the sample shows how easy it is to patch a few lines of code together an connect data with the inner workings of your Android based phone.
And this is really the true force behind an open mobile operating system like Android, because it allows you to modify the behaviour of your phone.

And – if you are a gadget addict like me – you bring the application to your next Android phone, when you decide to switch for the newest shiny Android phone on the market!

Pair blogging

For some years now, pair programming has proven to be a great way to get some high quality code crafted together and to be a great way to share the knowledge about how and why the code was constructed.
You get all the benefits of having more eyes on the code along with the ability to verbalize the solution you are putting together, which enhances your problem solving skills dramatically.
Chatting about your code and elaborating about how and why you solve a particular problem creates new ways of seeing new solutions.

Also – pair programming can often just be more enjoyable than programming alone, because – who REALLY wants to be stuck only with your worst possible critic, yes: Yourself ! :-)

Blogging with others
But how about pair blogging or even group blogging – do they offer the same benefits as pair programming ?

I’ve done a fair amount of pair blogging the last few years and even contributed to a blog with 4 authors working together on a series of blogs, and this has proven to be a good experience to us all.

The process of writing a new blog usually starts with one blogger writing up a draft in a very short time, thus providing the raw material for the blog post.
This first draft contains the core subject of the blog entry as perceived by the blogger and the process of constructing a common view on the blog subject then begins.

The second blogger picks up the thread and maybe starts by checking the facts stated in the blog post to see if they are correct. Or he/she adds comments about the views expressed in the blog and asks questions to expand on certain topics.

Some way during the blogging process, a Skype meeting is very handy to discuss the blog post and what to do about it.

The end product is usually a nicely written blog post, which has some other quality than blog posts like this one you’re reading right now – written by a single blogger, without other kind, but critical eyes on it before it is published :-)

A final thing on collaborative blogging is the positive side effect of the process, where new ideas spring to mind about other relevant blog themes.
When more brains are put to work, new ideas spark to life and new blog entries take life, perhaps when the original blog covers too many themes and needs to be taken apart.

If you do a lot of blogging already, I would highly recommend you to try out collaborative blogging to see the effects of it.

At the very least you will have someone to catch those tricky typos, that sneak by us all when writing blog posts alone ;-)

Chatting with Google App Engine

Google recently released a new version of their SDK for the Google App Engine(GAE) and starting with this release the SDK now includes support for XMPP services in applications.

The ability to use XMPP opens up a number of interesting possibilities to interact with Google Talk users, but could also prove very useful for other tasks, such as integrating applications as well.
But let’s first take a look at how the XMPP support can be put into use.

Sending XMPP messages

This small piece of Java code sends a message to a specific Google Talk user, in this case the (presumably?) non-existent user someone@gmail.com :-)

import com.google.appengine.api.xmpp.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.*;
import java.io.IOException;

public class XMPPSender extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws IOException {

        ServletOutputStream out = res.getOutputStream();

        //retrieve the service from the factory
        XMPPService xmppService = XMPPServiceFactory.getXMPPService();

        //specify who to chat with - JID is the "bare" XMPP address
        String recipient = "someone@gmail.com";
        JID jid = new JID(recipient);

        String msgBody = "Hi there!";

        //send an initial invitation to chat before sending messages
        xmppService.sendInvitation(jid);

        //build the message - in this case, just plain text.
        //XML is also supported
       Message msg = new MessageBuilder().withRecipientJids(jid)
                                          .withBody(msgBody).build();

        //send off the message and check if things went well
        SendResponse status = xmppService.sendMessage(msg);
        if (status.getStatusMap().get(jid) ==
                                  SendResponse.Status.SUCCESS) {
            out.println("That apparently went well...");
        } else {
            out.println("Something went wrong..");
        }
    }
}

On line 24 we send an invitation to the receiver of the message and the receiver must then accept the chat session before we can send messages.
A better way to do this, would be for the user to actively register with our application for chatting on a web page or by adding our the id of our XMPP client to the Google Talk roster.

JID names the target

As you can see in line 19, the JID is actually the address of the recipient of the message, also called the XMPP address.
An XMPP address could be a simple Gmail address like in this sample, but it could also target nodes specifying a resource to hit at the target domain.

Targetting specific resources at a domain requires a fully qualified JID like someone@example.com/machineXYZ, which is supported by the XMPP service on GAE.

lop-hierarchy1

The Linked Process Cloud (http://linkedprocess.org)

 

Using full JIDs you could use XMPP to target different nodes in a network and thus distribute processing on different nodes.
The Linked Process project extends XMPP to distribute processing on different computers and uses fully qualified JIDs to target a specific farm in their process cloud.

Receiving XMPP messages
Another feature of the new XMPP service is the ability to receive messages in your application.
If you want to receive XMPP messages you can do this by adding a few lines of code to a standard servlet as shown below.

import com.google.appengine.api.xmpp.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class XMPPReceiver extends HttpServlet {

    public void doPost(HttpServletRequest req, HttpServletResponse res)
            throws IOException {
        XMPPService xmppService = XMPPServiceFactory.getXMPPService();
        Message message = xmppService.parseMessage(req);

        JID fromId = message.getFromJid();
        xmppService.sendMessage(
                new MessageBuilder().
                        withBody("Your reply: " + message.getBody()).
                        withRecipientJids(fromId).
                        build());
    }
}

In this servlet we simply reply back to incoming messages by echoing the message to the sender after adding “Your reply:” in front of it.

To make this work, you will need to change your configuration files a bit.
The first change is in the appengine-web.xml where you need to specify that you want to receive inbound XMMP messages.

        xmpp_message

Next, you have to set up the XMPPReceiver servlet in your web.xml file which a specific URL

        xmppreceiver
        XMPPReceiver

        xmppreceiver
        /_ah/xmpp/message/chat/

The /_ah/xmpp/message/chat/ is the path that App Engine looks for to post XMPP messages to.

XMPP use cases

So the above samples simply deal with sending and receiving plain text messages to a Google Talk user.
The App Engine SDK does support exchanging XML messages as well, so you could exchange messages with another XMPP enabled application, for instance to start processes as done in the Linked Process project.

Other use cases could be to integrate applications such as Google Wave with chat using XMPP.
I put together a small application that notifies a Google Talk user of changes in a wave, so you can get notified if something changes inside a wave that you are participating in.

XMPP support in GAE is still relatively basic, but it is nonetheless a very powerful extension to the toolbox on the app engine and I believe that XMPP support is a vital ingredient in connecting different applications on the net.

Tags: ,

Growing up to be a Geek

Back in the seventies, a boy called Tommy was born.

Not a very common name in Denmark and not a name – as you might think – chosen to honor the English soldiers who freed Europe in the second world war, nor because of the great musical by the same name made by The Who.
No, the name was chosen by his big sister and she had picked the name from a television series for children in which an extremely strong red-haired girl was the main character.

The name of the girl was Pippi and she was at the time a very popular character among children, first in books and then on television.
Pippi was the geeky girl left all alone to herself in a huge old house and she ran into a lot of trouble or made the trouble herself. She always came out at the good end though because she had superpowers and was good to come up with new solutions that ordinary people would fail to see.
Tommy was the oh-so-nice and never misbehaving neighbour of Pippi and was always dragged into new adventures by the naughty girl next door :-)

Anyway, name aside, his childhood was rather happy but he felt a bit outside all the time.
He never liked the stuff that most kids do. He didn’t go to soccer, just because the rest of the boys in the class did.
He didn’t save every penny he had to get that motorbike that all the other boys wanted.

And he didn’t mix in with everyone else, even if it was what was expected of a “normal” boy to do….

So what did he do ?

He got a computer when he was 12. Started playing games on it but also did a lot of coding.
He bought strange German magazines with loads of pages containing machine code in hexidecimal to type in by hand and spend hours on end to type in the correct codes to see the outcome of all this code put into the computer by his hard work.

This hard task to make computers do “stuff” and finding the reward in that itself, is what led Tommy to be a geek.
And whatever he did as a grown-up, the effect of typing stuff into a computer and seeing the results of that work, always gave him a kick – even when it was “just” HTML coming out as web pages.

The magic would never disappear. A new “Hello world” sample in a new language, tool or IDE, the effect would always be “YES, I did it – that worked and felt great!”.
A new problem to solve that several people have failed to get cracked, leaving it all up to you – the geek. And you do it, you find that solution, that hidden button, setting or missing data and you save the day for tens, hundreds or thousands of people.
It takes skill, it takes talent – and, it can’t be taught!

 

Geek is for life, and it’s about life.

 

Welcome to the Geekhouse. Made by geeks, for geeks.

Geekhouse logo

Tags: