14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Peer-to-Peer Communication<br />

Introducing Android Instant Messaging<br />

280<br />

Largely as a result of security concerns, developer access to the GTalk IM Service<br />

has been restricted for Android SDK version 1.0. As a result, the functionality<br />

described in this section will not be available to developers using the fi rst full<br />

release of the Android SDK.<br />

Rather than remove the affected sections, they have been left here in full as a guide<br />

for use with future Android releases.<br />

Later releases of Android will expose a full suite of instant messaging functionality through an XMPP<br />

based IM Service. This will include management of contact rosters, presence notifi cation, and the transmission<br />

and receipt of instant messages.<br />

Google Talk (GTalk) is an instant messaging protocol for peer-to-peer (P2P) communication. Once connected,<br />

GTalk maintains a persistent socket connection with the GTalk server, meaning fast response<br />

times and low latency.<br />

This section is based on an early SDK implementation that used GTalk. GTalk is based on the XMPP<br />

protocol, but it’s a Google-specifi c variant that currently requires that users have a Gmail account.<br />

What makes the GTalk Service particularly interesting for developers is the ability to broadcast Intents<br />

over the air (OTA) between Android devices using data messaging. Data messages received by a remote<br />

device are re-broadcast as Intents locally, meaning that this mechanism lets you broadcast an Intent on<br />

a remote device.<br />

The GTalk Service can be used to create your own multi-user, social, or collaborative applications. It<br />

provides the framework for building a range of applications, including distributed emergency warning<br />

systems, dynamic route guidance applications, family social networks, and augmented reality gaming<br />

systems.<br />

Android will eventually include all the interfaces needed to create a Google Talk Instant Messaging client,<br />

including full control over presence management and subscription handling. You can, if you’re so<br />

inclined, build a replacement for the native client — or simply use the relevant components within your<br />

own applications.<br />

Using the GTalk Service<br />

Before you can access the GTalk Service, you need to import the gtalkservice library into your application<br />

with a uses-library tag inside the application node of the project manifest, as shown below:<br />

<br />

You also need to add the GTalk uses-permission tag, as shown in this XML snippet:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!