Pages

Showing posts with label Device. Show all posts
Showing posts with label Device. Show all posts

Friday 15 March 2013

Android Cloud To Device Messaging

[This post is by Wei Huang, who helped implement this feature. — Tim Bray]

In the just-launched Android 2.2, we’ve added a new service to help developers send data from servers to their applications on Android phones. Android Cloud to Device Messaging (C2DM) makes it easier for mobile applications to sync data with servers.

Most of the useful applications on your mobile phone use the Internet to keep users connected. Traditionally, many apps use polling to fetch data periodically. POP mail clients, for example, connect to the server every 15 minutes or so. Polling is fairly easy to implement, and works well in many situations. It’s tricky, though, to select the frequency: Poll too often, you may not see any new data, and create unnecessary stress on the server and network. Poll too rarely and the data on the device may become stale. Polling is especially problematic on mobile devices, because it consumes precious network bandwidth and battery life.

Having the server push messages to the client asynchronously may be a superior choice for getting the latest data to your applications, resulting in fresher data and more efficient use of the network and your battery. However, it’s also tricky to implement a good push solution, and it isn’t free as there is some overhead in maintaining the required connection. On a mobile device like an Android phone, implementing applications to receive these messages is tricky; you have to worry about patchy network coverage and zombie connections created when the wireless carrier’s routers time out connections that are idle for too long.

Many of the Google applications on Android already use push to keep their data fresh, for example Gmail, Contacts, and Calendar. Starting with Android 2.2, C2DM allows third-party developers to use the same service the Google apps do.

Here are a few basic things to know about C2DM:

  • It requires Android 2.2; C2DM uses Google services which are present on any device running the Android Market.

  • It uses existing connections for Google services. This requires the users to sign into their Google account on Android.

  • It allows 3rd party servers to send lightweight data messages to their apps. The C2DM service is not designed for pushing a lot of user content; rather it should be used like a “tickle”, to tell the app that there is new data on the server, so the app can fetch it.

  • An application doesn’t need to be running to receive data messages. The system will wake up the app via an Intent broadcast when the the data message arrives, so long as the app is set up with the proper Intent Receiver and permissions.

  • No user interface is required for receiving the data messages. The app can post a notification (or display other UI) if it desires.

It’s easy to use the C2DM API. Here is how it works:

  • To enable C2DM, an application on the device registers with Google and get a registration ID, and sends the ID to its server.

  • When the server needs to push a message to the app on the device, it posts the message via HTTP to Google’s C2DM servers.

  • The C2DM servers route the message to the device, and an Intent broadcast is sent to the app.

  • The app is woken up to process the message in its Intent Receiver.

  • The app can unregister with C2DM when the user no longer wants messages to be pushed to it.

That’s about it! All you need is a server that knows to talk HTTP, and an Android app that knows how to use the Intent APIs. Below are some code samples:

// Use the Intent API to get a registration ID// Registration ID is compartmentalized per app/deviceIntent regIntent = new Intent( "com.google.android.c2dm.intent.REGISTER");// Identify your appregIntent.putExtra("app", PendingIntent.getBroadcast(this /* your activity */,  0, new Intent(), 0);// Identify role account server will use to sendregIntent.putExtra("sender", emailOfSender);// Start the registration processstartService(regIntent);

The registration ID will be delivered back to your app via an intent broadcast with the Intent Action com.google.android.c2dm.intent.REGISTRATION. Here is a code sample to receive the registration ID.

// Registration ID received via an Intentpublic void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (“com.google.android.c2dm.intent.REGISTRATION”.equals(action)) { handleRegistration(context, intent); }}public void handleRegistration(Context context, Intent intent) { String id = intent.getExtra(“registration_id”); if ((intent.getExtra(“error”) != null) { // Registration failed. Try again later, with backoff. } else if (id != null) { // Send the registration ID to the app’s server. // Be sure to do this in a separate thread. }}

On the server side, your server needs to get a ClientLogin Auth token in order to talk to the C2DM servers. When it wants to push a message to the device, it can send an authenticated http POST with:

  • Authorization: GoogleLogin auth=

  • URL encoded parameters including the registration id, the data key/value pairs, a “collapse key” used for overriding old messages with the same key on the Google C2DM servers, and a few other optional params.

When you use the C2DM service, you no longer need to worry about dealing with flaky mobile data connections, or when the user isn’t connected to the internet (i.e. Airplane mode). C2DM keeps the messages in the server store, and delivers them when the device comes back online. Basically, you can leave all the hard work of designing a robust push service to Google. Your application can take advantage of push infrastructure we’ve already built and tested, and stay more connected to the internet. Best of all, you won’t ruin the users’ battery life.

Information about how to build C2DM enabled applications on Android is online at the code lab, and more will be coming as we approach general release.

Sunday 3 March 2013

HTC One X (Flagship Device)

HTC One X

HTC One X (Flagship Device)

The HTC One X is HTC‘s flagship device and currently the most powerful and feature-rich Android device on the market. I’ve had the device a little over a week now and thought I’d compile an objective criticism of the device. While the One X is a superb phone, it’s not perfect- there are a few issues with it and a few niggling problems that I have encountered since I received it.

There is a so-called ‘OS neutral’ tech website falling over themselves to knock the One X down, making the very most of the small issues the device has and comparing it unfavourably to the iPhone. I’ve noticed it is often called “too big” and “too powerful” (which can only hint that it’s actually just bigger and more powerful than an iPhone). There’s been criticism of the battery, the internal storage, the screen and the software. It just seems like they are protesting a little too much… perhaps their own preferences are feeling threatened? I wonder too that if the next Apple phone screen is bigger than the paltry 3.5? of the 4S and incorporates a quad-core processor it too will be deemed “an overkill”? Somehow I doubt it.

In light of this, I thought it might be an idea to give some balanced criticism of my own. Now, this is not going to be an embarrassing love-in between me and my Android, I intend to be objective and highlight the things that genuinely bother me as a user. I should also stress I’ve so far refrained from rooting my One X, and it is currently exactly as I began with it. So, in no particular order:

Battery
The internal, and therefore irreplaceable, battery lasts me approximately 11 hours with typical usage. While I went into this in a little detail in my review, I’ve monitored the battery since then quite closely. This 11 hours has improved slightly- the battery seems to get better with charging and calibrating (I don’t know the science behind this but it’s prudent to run the battery right down and leave it to charge while switched off a few times). I now get closer to 12 hours per charge with normal usage.

While I don’t think this is unreasonable for a smartphone, it’s still disappointing considering that the 5th ‘stealth’ processor is meant to improve battery life. It was in the midst of this funk that I discovered a good reason for this battery problem; essentially some of the software was compiled incorrectly resulting in the battery-saving effects being lost. The good news for One X users is, however, as a software problem, it can be rectified. Currently there is a method to do this without rooting but then it might be a safer option to wait for an HTC update which is supposedly imminent. This adjustment should result in up to 20% extra battery life, so for me this could mean a life of around 14 hours per charge, which is significantly better.

Screen Lag
This is a curious one. I find that, from my homescreen, there is always a tiny- almost unnoticeable- lag when you very first swipe either way. It always occurs when I return to the homescreen and only happens once. There is absolutely no slow-down or lag anywhere else that I have seen, and I’ve pushed it quite hard. Everything, from opening settings to the app draw, locking, unlocking, opening the camera or other apps is all done flawlessly, so I’m guessing this lag I have detected must also be in some way software-related.

Contacts
In my People, Groups and Call history, you can clearly see people’s numbers and pictures. However, in ‘Phone’ under recent calls, these number as listed as ‘Unknown’. It doesn’t really make sense, and is probably yet another small software issue, but it is a little weird.

Dropbox integration
I use Dropbox a lot, so I was chuffed to bits that I’d be getting an extra 23GB of storage with the service. Nothing could be easier for me to take screenshots of apps I’m reviewing and then upload to Dropbox for easy access on my laptop. However, since this upgrade to extra space, transfer seems to be incredibly sporadic and very unreliable.

In the past files upload automatically, however, now they can take forever to kick in- sometimes hours and hours. In the end, if I need the pictures on my computer immediately, I have to manually plug my One X and transfer via USB.  After using Dropbox regularly for a number of months now, this feels incredibly old fashioned and worryingly it means Dropbox is not reliable enough for me to use at the moment.

HTC Hub
I remember I logged into and made good use of the HTC Hub (a collecting pot of extra wallpapers, skins and ringtones, etc.) when I had my HTC Desire HD. It contained plenty of cool content that you could easily download straight onto you phone. However, now it seems all but empty. There are few ringtones but most often I get a little notice that says “No available content”. If that is the case and there is no content, why have it as an option at all?

Again, this is an incredibly minor niggle, and possibly something that could go unnoticed by many users, but for me it’s a little annoying as I’ve not been overwhelmed by the personalisation choices available pre-installed.