如何通过CallLog检查呼叫是否丢失或应答

时间:2013-09-18 07:03:29

标签: android performance android-layout android-intent android-contentprovider

我有一个内容观察员来进行通话记录更改

class CallContentObserver extends ContentObserver {

    Context context;

    public CallContentObserver(Handler handler, Context context) {
        super(handler);
        this.context = context;
    }


    @Override
    public void onChange(boolean selfChange) {
        super.onChange(selfChange);

        Cursor c = context.getContentResolver()
                              .query(CallLog.Calls.CONTENT_URI,null,null, null, "Calls._ID DESC");

       mCursor.moveToFirst();

        //How do I know the call is answered or missed ?

如上所示,在onChange()回调中,我想获取导致此onChange()被触发的最新通话记录。

我有两个问题:

1。我收到最新的通话记录项后,如何知道通话是应答还是错过?

2. 当我开始调用时,似乎onChange()被调用两次,但我只想在调用start时访问一次CallLog,如何摆脱这2次触发的问题onChange()

1 个答案:

答案 0 :(得分:0)

1

Integer type=cursor.getInt(cursor.getColumnIndexOrThrow(CallLog.Calls.TYPE));
switch(type){
    case CallLog.Calls.INCOMING_TYPE:
       /// do something
       break;
    case CallLog.Calls.OUTGOING_TYPE:
       /// do something
       break;
    case CallLog.Calls.MISSED_TYPE:
       /// do something
       break;
}

2。尝试将registerContentObservable()中的第二个参数设置为false,在那里查看p.3:   https://stackoverflow.com/a/10767455/2751697