简体   繁体   中英

Mark Missed Calls as read in Android Call Log

I am trying to mark the missed calls to read. I am trying the following to do so:

ContentValues values = new ContentValues();    
values.put(Calls.NEW, Integer.valueOf(0));    
if (android.os.Build.VERSION.SDK_INT >= 14){    
   values.put(Calls.IS_READ, Integer.valueOf(1));    
}

StringBuilder where = new StringBuilder();    
where.append(Calls.NEW);
where.append(" = 1 AND ");    
where.append(Calls.TYPE);    
where.append(" = ?");    
ContentResolver cr = getContentResolver();    
Uri baseUri = Uri.parse("content://call_log/calls");    
int numUpdated = cr.update(baseUri, values, where.toString(),new String[]{ Integer.toString(Calls.MISSED_TYPE) });

This actually marks the call read for my app but native android app is not detecting this and still show missed call badge and notification. How can we get this cleared.

First add permissions :

<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />

After you insert the function that changes the parameter is_read missed call we get from its id:

public void markCallLogRead(int id) {

    Uri CALLLOG_URI = CallLog.Calls.CONTENT_URI;
    ContentValues values = new ContentValues();
    values.put("is_read", true);
    try{
        getContentResolver().update(CALLLOG_URI, values, "_id=?",
                new String[] { String.valueOf(id) });
    }catch(Exception e){
        e.printStackTrace();
    }

}

You can't clear missing call notification. Google disabled access to this functionality to third party apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM