К сожалению, Notification Log uses метод getHistoricalNotifications
of NotificationManagerService
который требует 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
и отслеживать локально о новых уведомлений, отправленных приложений.