Development

I’ve been dabbling lately with Google’s Android platform for mobile development. While there aren’t any announced devices for the marketplace yet, it’s an extremely open platform, and one of the simplest mobile platforms to develop for that I’ve encountered.

The Android SDK still isn’t “officially” released yet, which means there are lots of undocumented quirks in the system and a few inconsistencies. Some of them you can figure out through trial and error. Some are just annoying. I recently managed to triumph over one of these quirks and thought I would share the fruits of that labor. In this case, it’s specifically how to add a contact, phone and email address into the built-in Address Book using Google’s Contacts ContentProvider.

Let’s start by adding a new person to the address book. Just a name and nothing else.

// create a new name
ContentValues values = new ContentValues();
values.put(Contacts.People.NAME, "Test Name");
// add it to the database
ContentURI newPerson = getContentResolver().insert(Contacts.People.CONTENT_URI, values);

The newPerson ContentURI that’s returned by the insert() call is null if something went wrong. If it’s not null, then it might look something like this
content://contacts/people/1
where the number 1 indicates the new ID of the person you just created.

If you don’t get back an ID number, then you can’t proceed, but assuming all went well, then you can use that new ID number to add other information to the existing record. For example, to add a phone number:

// assign the new phone number to the person
values.clear();
values.put(Contacts.Phones.PERSON_ID, newPerson.getPathLeaf());
values.put(Contacts.Phones.NUMBER, "(800) 466-4411");
// insert the new phone number in the database
getContentResolver().insert(Contacts.Phones.CONTENT_URI, values);

and to add an email address:

// assign an email address for this person
values.clear();
values.put(Contacts.ContactMethods.PERSON_ID, newPerson.getPathLeaf());
values.put(Contacts.ContactMethods.KIND, Contacts.ContactMethods.EMAIL_KIND);
values.put(Contacts.ContactMethods.TYPE,Contacts.ContactMethods.EMAIL_KIND_HOME_TYPE);
values.put(Contacts.ContactMethods.DATA, "test@test.com");
// insert the new email address in the database
getContentResolver().insert(newPerson.addPath(Contacts.ContactMethods.CONTENT_URI.getPath()), values);

Adding an email is tricky because it’s doesn’t match the same coding convention as adding a new contact or adding a new phone number. To make matters worse, this mismatch/inconsistency is not documented well in the existing docs, so it required a lot of trial and error to figure out how to do this without causing an internal error in the emulator.

Essentially, the issue is that for contacts and phone numbers you can use a ContentURI like this:
content://contacts/people
content://contacts/phones

to retrieve existing records or to add new records to the system.

However, for emails this is not the case. For emails, you have to use different URIs for each function, specifically:
retrieve emails – content://contacts/contact_methods
insert new emails – content://contacts/people/1/contact_methods
where the number 1 is the ID of the person you want to add the emails for.

I’m sure this will become documented more clearly as Android starts reaching a wider developer community. Until then, hopefully these code snippets will save some time for those Android developers struggling to get their apps finished before the March 2nd deadline for Google’s $25,000 Android competition.

Have fun coding.

Dec
17
Posted by wubbahed at 7:07 pm

Another co-worker got one of the new OLPC (One Laptop Per Child) machines in the mail today at work. We made another quick unboxing video so you can see the form factor of it.

Dec
10
Posted by wubbahed at 11:10 pm

Today I was downloading the new Channels Media Service application from Nokia Beta Labs to test it out and see what it has to offer. The interface is pretty clean, but one of the nicest things I noticed is that Channels makes use of the N95′s built in accelerometer. I recently showed you the Lightsaber demo, but Channels automatically orients the UI based on how you’re holding the device, similar to what Apple always shows off in their iPhone commercial. Here’s a demo of it in action.

When the N95 came out it didn’t have this functionality. In fact, it didn’t even talk about the accelerometer. But you know what? Nokia is slowly releasing software updates for this device, and they’re slowly showing people more and more things that can be done with this device. Every time there’s a new firmware update or I find a cool new application, it’s like getting a whole new phone. And I’m just not seeing that with the iPhone. Web apps? Yeah, they’re okay and can be helpful, but they’re more like widgets that sit on top of an internet connection rather than something that truly integrates with the device. The N95 is showing me more and more that it’s retaining its value over time, whereas the iPhone price drop just says that it was overpriced to begin with.

Dec
03
Posted by wubbahed at 2:37 pm

I’ve received a few comments recently about the UpcomingBirthdays widget not functioning correctly with Leopard.

I’m going to try and look into this some more and see what’s causing the problem, but it might take me a while to figure this one out. My day job is pretty busy this time of year, but more importantly, I don’t own Leopard and I’m a little hesitant to install it on my rockin’ awesome 12″ G4 Powerbook. If this is something I can fix quickly with HTML/CSS/Javascript, then hopefully I can get an update published quickly. But if it requires me to make changes in the plugin made with XCode, then that will take a bit longer to track down.

Stay tuned for updates.

UPDATE – Jan 2008 – If you are having trouble with this bug, please make sure that you are running the most current version of UpcomingBirthdays. You can download it from the sidebar, or by clicking here. Thanks.

Nov
30
Posted by wubbahed at 2:07 pm

Nokia Research has some sample software and plugins that you can use to capture raw data from the accelerometer found in the N95.

Accelero what with the wha? Let’s just say it detects the motion of your phone and that allows people to make applications like Lightsaber! Easily turn your N95 into a lightsaber. Check out this really rough video I made demonstrating it.

There was a nice comment posted tonight from the software engineer at Google who’s helping put together ZXing for Android. The good news is that the project has officially launched and you can read about it and download the 0.1 version here:

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

Also, note that they’ve set up a Google Group for ZXing, so that seems like the best place to continue the discussion….

At today’s MobileCampNYC, the whole group got a sneak peek at ZXing (Zebra Crossing), the barcode reader Google is planning to include in the Android SDK being released on Monday. There wasn’t much real information presented about Android itself, only about the bar code reader that will be included with the platform. Highlights include:

  • ZXing is an open source project, and will also be available as a standalone J2ME application for use on existing phones.
  • This is an early version of the reader, so don’t expect it to completely blow away some of the proprietary readers out here. As he put it, the goal is to set the minimum standard for open source bar code readers.
  • As it is an open source project, they’re actively looking for programmers to contribute

In general, there’s nothing here that really struck me as being any different than any other open source bar code reader. The most important thing I pulled out of the presentation is that Google is going to trial QR codes with print advertisers. This shows that Google is going to start actively pushing bar codes, but more importantly, it shows that they’re moving more into the print area, even if it is just to link people to online services.

Here are a few slides from the presentation. Though sparse, they might answer a few basic questions. For more details, you’ll just have to wait until Monday when the SDK and emulator are released.

ZXing - Google open source bar code reader

ZXing - Google open source bar code reader

Nov
10
Posted by wubbahed at 11:42 am

I’m a big fan of Yelp.com because of the richness of information plus the fact that they do a pretty good job of keeping it real and not getting bogged down with shills. Yelp also has a great mobile site that allows you to search through their listings and find something directly from your mobile phone. This service is particularly useful when you’re out and about in an unfamiliar area and need to find a good place nearby.

So I made this mashup. You can play with it here. Here’s a pic.

Yelp and Google Maps

The idea is that you can drag around the Google Map, and then when you click on a location, it will generate a QR code for Yelp’s website which allows you to see what kind of restaurants and nightlife are around that exact point on the map. Pretty cool, right?

In order to make this happen, there’s a lot of web services going on in the background. First, there’s the Google Map. Pretty basic and well documented. Once you click an overlay though, Google only gives you latitude and longitude of the point, but not an address. So I found this great Google Reverse Geocoder online and am using that to convert the lat/lon into a street address.

From there, you can build the URL for mobile.yelp.com, but it ends up being a VERY long URL and consequently, the bar code gets to be gigantic. So once I have the long URL then I’m sending it off to tinyurl.com to shrink it down. Finally, you take the tinyurl and generate the bar code using Kaywa.com.

Four web services, all done with a few lines of Javascript. If you look at the demo, then all of the source code can be seen there.

Oct
18
Posted by wubbahed at 6:07 pm

So even though Google’s own site doesn’t mention it, it appears that they’ve released an update of their Google Maps application for the N95. Anyone can get it by going to google.com/gmm, or you can just use this mobile code:

Google Maps on N95

This new version is light years ahead of the older one in terms of ease of use. The map scrolling is smoother and easier to use, and the interface is cleaner. Here’s a screenshot of the application in action:

Google Maps on the N95

I can even switch it to satellite view and see things like traffic patterns.

Google Maps on the N95

Hey, notice that text across the top of the screen? That’s right, I asked the program to show my location, so it’s activated the GPS receiver on the N95 and is attempting to get a lock on the position. Once it has a lock, then it zooms in and centers on your location (indicated by a blinking blue dot).

Google Maps on the N95

I love it.

Oct
09
Posted by wubbahed at 3:37 pm

It seems that Nokia is taking a page from the record industry and putting out all of their big releases on Tuesdays.

The second big release today was the developer beta for Nokia Web Widgets. This release is really meant for tech developers only, unless of course, you want to download and install a 336MB C++ SDK (requires login), but the point of it all is that pretty soon you’ll be able to install widgets on your S60 mobile phone.

What some people might not realize is that the web browser on S60 devices is based on WebKit, which is the same codebase that’s used on Safari on Mac OS X and the Dashboard widgets built into the Mac OS. So as I test, I decided to see how easy it would be to try and get my GuitarChords widget for Dashboard up and running on the new beta for S60.

After installing the developer beta, I had to make a few changes to the info.plist file, and disable the custom code for the GuitarChords Plugin, and voila!

GuitarChords on S60

The application showed up just fine in the emulator and when I clicked on it, the widget launched on the device!

GuitarChords on S60

Obviously, I’ve got to do some work on the UI to get it to scale properly, and I’ll probably need to re-think the interaction so that it’s more appropriate for mobile devices, but this isn’t a bad start for 20 minutes of work… More soon….