2016-03-26 11 views
4

Androidでは、現在アクティブな通知のリストをNotificationListenerServiceで取得できます。ただし、古い通知のリスト(これ以上アクティブでないことを意味する)を取得することは可能です。Android - 古い通知のリストを取得する

Android OSには、通知ログという機能があります。私のアプリケーションのためだけに同じ内容のものを得ることは可能ですか?または、この種の履歴を保持するためにこれをアプリケーションレベルで処理する必要がありますか?

答えて

2

残念なことに通知ログusesgetHistoricalNotificationsNotificationManagerServiceは、ACCESS_NOTIFICATIONSの許可が必要です。この理由は、システムのアプリケーションに予約されています:

/** 
* System-only API for getting a list of recent (cleared, no longer shown) notifications. 
* 
* Requires ACCESS_NOTIFICATIONS which is signature|system. 
*/ 
@Override 
public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) { 
    // enforce() will ensure the calling uid has the correct permission 
    getContext().enforceCallingOrSelfPermission(
      android.Manifest.permission.ACCESS_NOTIFICATIONS, 
      "NotificationManagerService.getHistoricalNotifications"); 

    StatusBarNotification[] tmp = null; 
    int uid = Binder.getCallingUid(); 

    // noteOp will check to make sure the callingPkg matches the uid 
    if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg) 
      == AppOpsManager.MODE_ALLOWED) { 
     synchronized (mArchive) { 
      tmp = mArchive.getArray(count); 
     } 
    } 
    return tmp; 
} 

唯一の現実的な選択肢は、NotificationListenerServiceを作成する方法onNotificationPostedを実装し、アプリケーションによって投稿新しい通知については、ローカルに追跡することがあります。

関連する問題