Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-删除未接来电通知_Android_Telephony - Fatal编程技术网

Android-删除未接来电通知

Android-删除未接来电通知,android,telephony,Android,Telephony,是否仍然可以通过代码删除未接来电通知?并以某种方式从通话历史记录中删除上次未接来电?是的,这是可能的。请尝试以下操作: Uri UriCalls = Uri.parse("content://call_log/calls"); Cursor cursor = getApplicationContext().getContentResolver().query(UriCalls, null, null, null, null); 正在读取呼叫日志项 if(cursor.getCount() &g

是否仍然可以通过代码删除未接来电通知?并以某种方式从通话历史记录中删除上次未接来电?

是的,这是可能的。请尝试以下操作:

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" />

注:请参阅此通话记录以了解更多信息

使用上述代码可以获得所需的结果。

请参阅
您可以通过调用
cancel(ID)
calcelAll()
清除通知栏来清除错过的调用。

对于要从日志中删除最后一次调用的部分,您需要将删除项的方法移动到一个类中,该类是Thread类的子类。这允许您将其设置为睡眠一小段时间,以允许Android在您运行删除查询之前实际写入呼叫日志。我遇到了相同的问题,但通过以下代码成功解决了此问题:

public class DelayClearCallLog extends Thread {

    public Context context;
    public String phoneNumber;

     public DelayClearCallLog(Context ctx, String pNumber){

            context = ctx;
            phoneNumber = pNumber;
        }

     public void run() {
         try {
             sleep(2000);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }

         clearCallLog(context, phoneNumber);
     } 
 public void clearCallLog(Context context, String phoneNumber) {
         // implement delete query here
     }
}
然后按如下方式调用该方法:

DelayClearCallLog DelayClear = new DelayClearCallLog(context, phoneNumber);
DelayClear.start();

好的,这是可行的,但是我想删除的号码的最后一个来电被保存了。它也不会从通知栏消失?有什么建议吗?但这只有在你自己开发通知的情况下才行?我想清除Android的未接来电通知!