OK – A communication app – I

OK - Communication App LogoI’m glad to announce that our communication app for android: OK has just been released.

OK is a communication app made for lazy people, with the aim of easing the communication. Basically, it allows you customise a predefined list of the messages that you use more often, so that you can use them rather than type them all the time.

Our aim is to let the app learn from each individual usage, and automatically generate a relevant list of messages for each recipient, time and situation. There is still la long way to get there, but we already have the basics in place.

Please, feel free to try out the app and don’t forget to give us some feedback, as we are looking forward to hear peoples thoughts of it.

Enough introduction, this post is the first of a series where we will show you step by step how we built the app, along with all the challenges we faced, and our approaches to solve them.

To begin with, since this is a communication app, we need to display the list of contacts.

In order to do load the contacts we need to do add the following in your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_CONTACTS" />

Then, create a new method in your activity to fetch all the contacts and put them into a List:

public List<ContactItem> getDataForListView(Context context)
{
    List<ContactItem> contactsList = new ArrayList<ContactItem>();
    Cursor cursor;

    cursor = context.getContentResolver().query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
            null,
            ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
    while (cursor.moveToNext()) {
        String contactName = cursor
                .getString(cursor
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        String storedNumber = cursor
                .getString(cursor
                        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        String phNumber = new String(storedNumber).replace(" ", "");
        int contactID = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID));
        ContactItem contact = new ContactItem(contactName, phNumber, contactID);
        contactsList.add(contact);
    }
    cursor.close();

    return contactsList;
}

We use ContactItem which is a custom class to allow us to store the name, id and phone number of the contact. The class is defined as:

public class ContactItem
{

    String name;
    String phone;
    int id;

    public ContactItem(String name, String phone, int id)
    {
        super();
        this.name = name;
        this.phone = phone;
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getPhone()
    {
        return phone;
    }

    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }
}

Now, we have all the contacts into a list, and we can easily display them inside a list view, but first we have to solve the following problem:
We are trying to use the phone number as the unique identifier of the users, but that would only work if they are in international format (including the country code), and unfortunately, there are many contacts that doesn’t have the full number stored in the device.

We needed a mechanism to convert or validate the numbers so that they are all in a standard format, otherwise we wouldn’t have a reliable way to identify the contacts as registered users of the app.

Stay tuned to find out how we solved that problem… and much more!

Leave a Reply

Your email address will not be published. Required fields are marked *