Im trying to get the icon of active notification on AndroidTV. I need to encode it to base64 and send it to react native.
The icon is stored as blob type and decoded looks like this
android.graphics.drawable.Icon com.android.systemui/
which looks like just a path to the icon, but i would need to get the real icon and encode it to base 64.
Im retrieving data like this:
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());
}
Getting title and text works fine, but encoding the icon bytes to base64 returns
HgAAAGEAbgBkAHIAbwBpAGQALgBnAHIAYQBwAGgAaQBjAHMALgBkAHIAYQB3AGEAYgBsAGUALgBJAGMAbwBuAAAAAAACAAAAFAAAAGMAbwBtAC4AYQBuAGQAcgBvAGkAZAAuAHMAeQBzAHQAZQBtAHUAaQAAAAAALwUIAQAAAAAFAAAA
which can be decoded to
android.graphics.drawable.Icon com.android.systemui/
How can I get that icon and not just the path? Thank you.
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;
}