NotificationListenerService 获取通知图标? [英] NotificationListenerService get Notification Icon?

查看:21
本文介绍了NotificationListenerService 获取通知图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扩展新的 (SDK18, JB-4.3) NotificationListenerService 的服务中,我想获得通知的状态栏图标.

In a Service extending the new (SDK18, JB-4.3) NotificationListenerService, I'd like to get the Notification's status bar icon.

mStatusBarNotification.getNotification().icon 返回状态栏可绘制的资源 ID,但该资源 ID 自然不在我的应用程序的范围/资源内.还有 mStatusBarNotification.getNotification().largeIcon(返回一个 Bitmap),但这不是为所有通知设置的并返回错误"图标(扩展通知中的图像抽屉).

mStatusBarNotification.getNotification().icon returns the resource id of the status bar drawable, but that resource id is naturally not within my app's scope/resources. There's also mStatusBarNotification.getNotification().largeIcon (returning a Bitmap), but that's not set for all notifications and returns the "wrong" icon (the image in the expanded notification drawer).

推荐答案

StatusBarNotification 上使用 getPackageName() 来找出发布 Notification<的应用程序/代码>.然后你可以 使用 createPackageContext() 获取该包的 Context,然后使用该 Context 检索图像(例如,通过 getResources()).

Use getPackageName() on StatusBarNotification to find out the app that posted the Notification. You can then use createPackageContext() to get a Context for that package, then use that Context to retrieve the image (e.g., via getResources()).

这篇关于NotificationListenerService 获取通知图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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