android - 从 StatusBarNotification 检索小图标作为位图
问题描述
我正在尝试在
NotificationListenerService
.
我找到了notification.getSmallIcon()
返回 a 的函数android.graphics.drawable.Icon
。怎么可能Bitmap
从那个图标获得一个?
解决方案
您需要在图标上使用loadDrawable
或loadDrawableAsync
,它将返回一个可绘制对象。
loadDrawable
在 API 级别 23 中添加public Drawable loadDrawable
(Context context)
返回Drawable
可用于在此图标内绘制图像的 a,必要时构建它。根据图像的类型,这可能不是您希望在 UI 线程上执行的操作,因此请考虑改用 loadDrawableAsync。
如下所示
Icon icon = notification.getSmallIcon();
Bitmap bitmap = icon.loadDrawable(context);
然后您可以从下面的stackoverflow链接将drawable转换为位图有很多答案如何将drawable转换为位图
推荐阅读
- html - React HTML 选择选项在 Chrome 中不起作用
- ios - AVPlayerLayer 锁屏控制
- angular - TypeScript 中 TSLint 的意外行为
- angular - 如何在 LoadingIndicator 的 customView 属性中传递图像?
- azure - 支持请求贡献者角色的 PoC
- java - 在 Java 中获取值 - request.getParameter
- c++ - 如何检查 QTreeWidget 中的标志状态?
- mysql - 使用“加载数据文件”时的参数查询
- windows - 无法排除 C1.WPF.4.dll。来自依赖项和安装程序项目
- angular - 在 mat-horizontal-stepper 标签之外拥有所有 mat-horizontal-stepper 步骤的主体