Skip to content Skip to sidebar Skip to footer

Android Content Observer - Onchange Method Check If Last Call Is Missed Call Or Not

I am working on an android app and I need to increment the incoming missed calls. I registered a ContentObserver. How can I check in the onChange method if the call is a missed cal

Solution 1:

I would suggest to try the following code in order to determine 'if last call is missed call or not':

@OverridepublicvoidonChange(boolean selfChange, Uri uri) {

    if (null == uri) {
        onChange(selfChange);
        return;
    }

    super.onChange(selfChange, uri);

    finalCursorc= context.getContentResolver().query(uri,null,null, null, null);
    finalinttype= c.getColumnIndex(CallLog.Calls.TYPE);
    finalintdircode= c.getInt(type);

    switch (dircode) {
        case CallLog.Calls.MISSED_TYPE:
            flag++;
            break;
    }
}

It would be faster than checking all calls in case if You need to check only latest call. However, if where will be no uri, then provided way looks fine.

Another suggestion is to implement Service to do checking of missed calls count, so You will not have long processing in ContentObserver.

Post a Comment for "Android Content Observer - Onchange Method Check If Last Call Is Missed Call Or Not"