gpt4 book ai didi

android - 有没有办法获取设备通知历史记录?

转载 作者:IT老高 更新时间:2023-10-28 13:35:26 26 4
gpt4 key购买 nike

我正在开发一个使用情况统计应用程序,我想知道其他应用程序如何访问设备通知历史记录

现在我正在使用 NotificationListenerService,但这只能处理收到的新通知,而不是过去的通知。我检查了 Android DOC 并发现了一些“仅限系统”的方法,例如 getHistoricalNotifications(),或者需要 ACCESS_NOTIFICATION 权限。

问题是有一些应用程序实际上可以访问通知历史数据。

Android DOC 还在 Android Q 上展示了一个名为 NotificationStats 的新 API,但目前不可用。

有什么建议吗?这甚至可能以一种非 hacky 的方式实现吗?

最佳答案

ActionDash 显示此 enter image description here

正如您所提到的,getHistoricalNotifications 是一个系统级 API,只能由系统应用访问,因此作为系统应用的 Google Digital Wellbeing 可以显示这些。

所以我认为没有办法获取 3rd 方应用的通知历史记录。

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

关于android - 有没有办法获取设备通知历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55314906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com