Android Tutorial

(avery) #1
Android Tutorial 331

audio files at this location. By using the managedQuery() method,
we get a managed Cursor as a result. We then examine our Cursor
for the results.

Using the CallLog Content Provider

Android provides a content provider to access the call log on the
handset via the class android.provider.CallLog. At first glance, the
CallLog might not seem to be a useful provider for developers, but
it has some nifty features. You can use the CallLog to filter recently
dialed calls, received, and missed calls. The date and duration of
each call is logged and tied back to the Contact application for
caller identification purposes.

The CallLog is a useful content provider for customer relationship
management (CRM) applications. The user can also tag specific
phone numbers with custom labels within the Contact application.

To demonstrate how the CallLog content provider works, let’s look
at a hypothetical situation where we want to generate a report of
all calls to a number with the custom labeled
HourlyClient123.Android allows for custom labels on these
numbers, which we leverage for this example:

String[] requestedColumns = {
CallLog.Calls.CACHED_NUMBER_LABEL,CallLog.Calls.DURATION
};
Cursor calls = managedQuery(
CallLog.Calls.CONTENT_URI, requestedColumns,
CallLog.Calls.CACHED_NUMBER_LABEL



  • “ = ?”, new String[] { “HourlyClient123” } , null);
    Log.d(DEBUG_TAG, “Call count: “ + calls.getCount());
    int durIdx = calls.getColumnIndex(CallLog.Calls.DURATION);
    int totalDuration = 0;

Free download pdf