2014-10-20 91 views
0

我不得不從通知欄在onCreate刪除未接電話,怎麼過將所有「未讀」「讀」是不夠的清除錯過了通知欄通話

public void resetMissingCalls() { 
    Runnable reset = new Runnable() { 

     @Override 
     public void run() { 
      String[] projection = { CallLog.Calls._ID, 
        CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE }; 
      String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE 
        + " AND " + CallLog.Calls.NEW + "=1"; 
      Cursor c = getContentResolver().query(
        CallLog.Calls.CONTENT_URI, projection, where, null, null); 
      Utils.PrintInfo("CALLS " + c.getCount()); 

      c.moveToFirst(); 
      if (c.getCount() > 0) { 
       do { 
        Utils.PrintInfo(c.getString(c 
          .getColumnIndex(CallLog.Calls._ID)) + " coursor "+c.getString(c 
          .getColumnIndex(CallLog.Calls.CACHED_NUMBER_LABEL))); 
        setAsRead(c.getString(c 
          .getColumnIndex(CallLog.Calls._ID))); 
       } while (c.moveToNext()); 
      } 
      c.close(); 
     } 
    }; 
    new Handler().post(reset); 
} 

如何清除這個不使用NotificationManager.cancelAll()

如果你想取消所有通知使用

NotificationManager notifManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
notifManager.cancelAll(); 

+0

您是否獲得ID爲您需要刪除通知? – 2014-10-20 09:26:37

+0

nope即時消息不,但也許我可以但我不知道如何從通知本身得到id – Mariusz 2014-10-20 09:33:43

+0

您可以使用[getActiveNotification](http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications %28%29),解析您收到的數據,並檢查確定是否有未接電話通知的方式,然後取消該通知。 – 2014-10-20 09:38:38

回答

0

但如果你有通知ID使用

notifManager.cancel(notifyId); 

,如果你想聽聽Android通知,您需要註冊AccessibilityService

你可能要看看這個answer

+0

的另一件事,但請告訴我如何在創建通知時通知(int id,通知通知),以便從頂部工具欄獲得通知的ID – Mariusz 2014-10-20 09:34:54

+0

編號,你可以用它來取消這個通知,在這裏閱讀關於這個http://developer.android.com/reference/android/app/NotificationManager.html#notify(int,android.app.Notification) – 2014-10-20 09:40:51

+0

但我不創建關於缺少呼叫的通知這是系統缺少呼叫通知 – Mariusz 2014-10-20 09:46:49