Android-检索旧通知列表 [英] Android - retrieve list of old notifications

查看:94
本文介绍了Android-检索旧通知列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Android上,您可以使用 NotificationListenerService 检索当前活动通知的列表.但是,可以检索旧通知列表(意味着不再活动).

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).

我知道Android操作系统中有一个名为通知日志的功能.是否有可能仅为我的应用程序获得相同的内容?还是必须在应用程序级别进行处理才能保留这种历史记录?

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?

推荐答案

不幸的是,通知日志

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;
}

唯一可行的选择是创建一个 NotificationListenerService ,实现方法

The only viable option is to create a NotificationListenerService, implement the method onNotificationPosted and keep track locally about new notifications posted by apps.

这篇关于Android-检索旧通知列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆