Reputation: 6772
I know that on Android you can retrieve a list of current active notifications with NotificationListenerService. However is it possible to retrieve a list of old notifications (meaning not active anymore).
I know that there is a feature in the Android OS called Notification Log. Is it possible to get kind of the same content just for my application only? Or does this have to be handled on the application level to keep that kind of history?
Upvotes: 6
Views: 3056
Reputation: 32790
Unfortunately Notification Log uses the method getHistoricalNotifications
of NotificationManagerService
that requires ACCESS_NOTIFICATIONS
permission. For this reason it is reserved to system apps:
/**
* 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;
}
The only viable option is to create a NotificationListenerService
, implement the method onNotificationPosted
and keep track locally about new notifications posted by apps.
Upvotes: 5