【问题标题】:AndroidTV get notification iconAndroidTV 获取通知图标
【发布时间】:2020-08-26 19:34:42
【问题描述】:

我正在尝试在 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, 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/

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

【问题讨论】:

    标签: java android android-notifications android-drawable android-tv


    【解决方案1】:
    private static Icon getIconFromBytes(byte[] blob) {
            Parcel in = Parcel.obtain();
            Icon icon = null;
            if (blob != null) {
                in.unmarshall(blob, 0, blob.length);
                in.setDataPosition(0);
                icon = in.readParcelable(Icon.class.getClassLoader());
            }
    
            in.recycle();
            return icon;
    }
    
    

    【讨论】:

    猜你喜欢
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    相关资源
    最近更新 更多