163
CHAPTER 8: APIs
intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE)
// starting at API level 15, this is needed:
intent.putExtra("finishActivityOnSaveCompleted", true)
// now put any data to update, for example
intent.putExtra(Intents.Insert.EMAIL, newEmail)
...
startActivity(intent)
Synchronizing Contacts
At this place, we provide a brief outline on what to do if you want to write a contacts
synchronization app between your device and a server.
1. Build a subclass of android.app.Application and register it as name
inside the tag of the file AndroidManifest.xml. Inside
its onCreate() callback, instantiate a SyncAdapter and provide for a
method a SyncAdapter service can fetch this instance.
2. Build a bindable service component the system can use for
synchronization.
3. Implement the SyncAdapter, for example by subclassing an
AbstractThreadedSyncAdapter.
4. Provide an XML file to tell the system about the adapter. The
procedure gets described in the online API documentation of
AbstractThreadedSyncAdapter.
5. Optionally provide a service for authentication. The AccountManager
starts this service to begin the authentication process. When the
system wants to authenticate a user account for the application’s
sync adapter, it calls the service’s onBind() method to get an IBinder
for the authenticator.
6. Optionally provide a subclass of AbstractAccountAuthenticator,
which handles requests for authentication.
Using Quick Contact Badges
Quick contact badges allow you to use a GUI widget that your user can tap to see a
contact’s details and take any suitable action from there such as sending an e-mail, issuing a
call, or whatever makes sense. This details screen gets presented by the system; you don’t
have to implement it in your app. See Figure
8-6
.
Do'stlaringiz bilan baham: |