AndroidTV获取通知图标

问题描述

我正在尝试在AndroidTV上获取活动通知的图标。我需要将其编码为base64并发送给它以响应本机。

该图标存储为Blob类型,并且已解码,如下所示:

android.graphics.drawable.Icon  com.android.systemUI/

看起来只是图标的路径,但我需要获取真实的图标并将其编码为base 64。

我正在这样检索数据:

private static final Uri NOTIF_CONTENT_URI = Uri.parse(
            "content://com.android.tv.notifications.NotificationContentProvider/" +
                    "notifications");

final String[] projection = { TITLE,TEXT,SMALL_ICON};

Cursor c = _reactContext.getContentResolver().query(NOTIF_CONTENT_URI,projection,null,null);

if (c != null && c.movetoFirst()) {
     do {
         String title = c.getString(c.getColumnIndex(TITLE));
         String text = c.getString(c.getColumnIndex(TEXT));
         byte[] smallIconBytes = c.getBlob(c.getColumnIndex(SMALL_ICON));
     } while (c.movetoNext());
}

获取标题和文本效果很好,但是将图标字节编码为base64返回

HgAAAGEAbgBkAHIAbwBpAGQALgBnAHIAYQBwAGgAaQBjAHMALgBkAHIAYQB3AGEAYgBsAGUALgBJAGMAbwBuAAAAAAACAAAAFAAAAGMAbwBtAC4AYQBuAGQAcgBvAGkAZAAuAHMAeQBzAHQAZQBtAHUAaQAAAAAALwUIAQAAAAAFAAAA

可以解码为

android.graphics.drawable.Icon  com.android.systemUI/

如何获取该图标,而不仅仅是路径?谢谢。

解决方法

private static Icon getIconFromBytes(byte[] blob) {
        Parcel in = Parcel.obtain();
        Icon icon = null;
        if (blob != null) {
            in.unmarshall(blob,blob.length);
            in.setDataPosition(0);
            icon = in.readParcelable(Icon.class.getClassLoader());
        }

        in.recycle();
        return icon;
}