Android - 删除未接来电通知

标签 android telephony

有没有办法通过代码删除未接来电通知?并以某种方式从通话记录中删除最后一个未接来电?

最佳答案

是的,这是可能的。试试这个:

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

正在读取通话记录条目...

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();
    }
}

正在删除通话记录中的条目...

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

权限:

<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

注意:请引用这个doc通话记录更清晰。

使用上面的代码你可以得到想要的结果。

关于Android - 删除未接来电通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736613/

相关文章:

android - 统计远端电话响铃次数

android - 查找来电者 Android 手机信息

java - 为什么我无法将NavigationOnClickListener 设置为工具栏?

android - 直接嵌套线性布局只显示第一个 subview

android - 丢失了我的证书文件,如何在 playstore 中发布应用程序

Android Espresso,测试前唤醒设备。如何使用自定义 list 进行测试?

java - WebView 电话 : open chooser telephone or sms

php - Asterisk -哪个 Asterisk PHP库?

c++ - 标准可拨号码格式 (c++ tapi)

android - 选择器与 android :drawable ="@color/transparent" attribute