CallLog Content Provider

Following code demonstrates retrieving information such as caller label, duration of the call using CallLog Content Provider.

Write the following code in onCreate() method.

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

Log.i(DEBUG_TAG, "Call count: " + calls.getCount());

int durIdx = calls.getColumnIndex(CallLog.Calls.DURATION);
int totalDuration = 0;
calls.moveToFirst();
while (!calls.isAfterLast())
{
	Log.i(DEBUG_TAG, "Duration: " + calls.getInt(durIdx));
			totalDuration += calls.getInt(durIdx);
	calls.moveToNext();
}
Toast.makeText(getApplicationContext(),
		"inside while " + totalDuration, 20).show();
Log.i(DEBUG_TAG, "Call Duration: " + totalDuration);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s