android content observer - onChange method check if last call is missed call or not

北慕城南 提交于 2019-12-01 12:48:38

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

@Override
public void onChange(boolean selfChange, Uri uri) {

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

    super.onChange(selfChange, uri);

    final Cursor c = context.getContentResolver().query(uri,null,null, null, null);
    final int type = c.getColumnIndex(CallLog.Calls.TYPE);
    final int dircode = 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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!