NotificationListenerService得到通知图标? [英] NotificationListenerService get Notification Icon?
问题描述
在扩展新(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()。图标
返回状态栏绘制的资源ID,但资源ID自然是我的应用程序的范围/资源范围内。还有 mStatusBarNotification.getNotification()。largeIcon
(返回位图
),但是这并不适用于所有的通知,并返回设置错误图标(在扩展的通知抽屉的图像)。
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).
推荐答案
使用 getPackageName()
在 StatusBarNotification
来找出公布的通知
应用程序。然后,您可以<一href="http://developer.android.com/reference/android/content/Context.html#createPackageContext%28java.lang.String,%20int%29"相对=nofollow>使用 createPackageContext()
获得上下文
该程序包,然后用该上下文
检索图像(例如,通过 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屋!