2011-04-06 53 views
1

我從始終在後臺運行的服務創建狀態欄通知。 如果用戶在5分鐘內沒有點擊它,我想取消通知。pendingIntent getBroadcast:檢查用戶是否已經點擊了狀態欄通知

那麼如何檢查狀態欄通知是否仍然有效?

我發現我們可以在pendingIntent getBroadcast和FLAG_NO_CREATE,如果它返回Non Null那麼它意味着狀態欄通知仍然是活動的。但對我來說,即使狀態欄通知處於活動狀態,alwasy仍會返回null。請找到下面的代碼。

請讓我知道如果我做錯了什麼。

代碼:

/* Notification intent creation */ 

Intent notificationIntent = new Intent(Intent.ACTION_MAIN, null); 
      notificationIntent = new Intent(Intent.ACTION_MAIN, null); 
      notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

      final ComponentName cn = new ComponentName("com.ActivityTrackingUI", "com.ActivityTrackingUI.Main"); 
      notificationIntent.setComponent(cn); 

/* check */ 

      if(PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_NO_CREATE) != null) 
      { 
       Log.e("","notification present"); 
      } 
      else 
       Log.e("","notification not present"); 

始終打印通知不存在

回答