Android 5.1推送通知图标为空白

Sha*_*zan 15 android push-notification parse-platform

当使用Parse进行推送通知时,我们的应用程序始终显示应用程序的启动器图标.在最新的Android 5.1版本中,图标显示为空白(白色方块).

我尝试在元数据中设置图标:

<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/noti_icon"/>
Run Code Online (Sandbox Code Playgroud)

根据这里的问题

但似乎没有任何效果.有任何想法吗?

Pel*_*nes 12

您必须在Android Lollipop 5.0或更高版本下使用透明和白色图标.您可以扩展ParsePushBroadcastReceiver类并覆盖这两种方法,以使您的通知图标与这些Android API兼容.

    @Override
protected int getSmallIconId(Context context, Intent intent) {
    return R.drawable.your_notifiation_icon;
}

@Override
protected Bitmap getLargeIcon(Context context, Intent intent) {
    return BitmapFactory.decodeResource(context.getResources(), R.drawable.your_notifiation_icon);
}
Run Code Online (Sandbox Code Playgroud)

请记住自定义代码以支持Lollipop和以前的API.

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        return BitmapFactory.decodeResource(context.getResources(), R.drawable.your_notifiation_icon_lollipop);
    }
    else{
        return BitmapFactory.decodeResource(context.getResources(), R.drawable.your_notifiation_icon);
    }
Run Code Online (Sandbox Code Playgroud)


Muz*_*ant 2

它与 Parse 或推送通知无关,而与 Android 5.0 如何处理通知图标有关。有关详细信息,请参阅此相关问题: 通知栏图标在 Android 5 Lollipop 中变白