Search code examples
androidbroadcastreceiverandroid-broadcastphone-call

how to detect if incomming miss calls are read


I am currently detecting missed calls using:

String[] projection = new String[]{CallLog.Calls.NUMBER,
                CallLog.Calls.TYPE,
                CallLog.Calls.DURATION,
                CallLog.Calls.CACHED_NAME,
                CallLog.Calls._ID};

        String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE+" AND NEW = 1";                 

Cursor c = context.getContentResolver().query(CallLog.Calls.CONTENT_URI,projection,where, null, null);      c.moveToFirst();            
Log.d("CALL", ""+c.getCount());         
if(c.getCount() > 0) 
// code that displays in a textview the number of missed calls;

Using a flag I am displaying missed calls to the client.

Is there a way I can reset the textview value to 0 if the missed calls are read?

Is there a broadcast receiver or something that announce me when missed calls are read?


Solution

  • To get information on missed calls. You can use following.

     String[] projection = { CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
     String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE + " AND " + CallLog.Calls.NEW + "=1";         
     Cursor c = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, projection, where, null, null);
    

    In this cursor you will get all details of Missed calls. Then you have to make another call to check if call is read or not. I think using TimerTask or using AlaramManager you can fill cursor once again. Or if you are displaying in your activity then try to fill it once again when that activity is started.

    Hope it will help you.