Skip to content Skip to sidebar Skip to footer

Unable To Get Recently Dialled Numbers

I'm working in Android application where I have to fetch last 20 dialled calls. Here's is my activity: public class Calls extends Activity { public void onCreate(Bundle savedI

Solution 1:

Most probably you are missing a permission:

<uses-permissionandroid:name="android.permission.READ_CONTACTS" />

Or your loop is not correct, try this kind of loop instead:

int count = 0;
if (cursor.moveToFirst()) {
  do {
    // Read your row here

    ++count;
  } while (cursor.moveToNext() && count<20);
}
cursor.close();

It would be more efficient also to limit the number of rows directly in the query rather than in the loop itself:

managedQuery( CallLog.Calls.CONTENT_URI, null, 
        CallLog.Calls.TYPE + " = " + CallLog.Calls.OUTGOING_TYPE, 
        null, strOrder + " LIMIT 0, 20");

Post a Comment for "Unable To Get Recently Dialled Numbers"