Android - remove missed call notification

后端 未结 3 1556
再見小時候
再見小時候 2021-01-06 18:43

is there anyway to remove a missed call notification by code? And somehow remove the last missed call from call history?

3条回答
  •  失恋的感觉
    2021-01-06 19:17

    yes, it is possible.Try this:

    Uri UriCalls = Uri.parse("content://call_log/calls");
    Cursor cursor = getApplicationContext().getContentResolver().query(UriCalls, null, null, null, null);
    

    Reading call log entries...

    if(cursor.getCount() > 0){
        cursor.moveToFirst();
        while(!cursor.isAfterLast()){
            String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)); // for  number
            String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name
            String duration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));// for duration
            int type = Integer.parseInt(cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going
            cursor.moveToNext();
        }
    }
    

    Deleting entry in call log...

    String queryString= "NUMBER='" + number + "'";
    if (cursor.getCount() > 0){
            getApplicationContext().getContentResolver().delete(UriCalls, queryString, null);
    }
    

    Permission:

    
    
    

    Note: Please refer this doc over call log for more clearity.

    Using the above code you can get the desired result.

提交回复
热议问题