Android 5.1推送通知图标为空白 [英] Android 5.1 push notification icon is blank

查看:138
本文介绍了Android 5.1推送通知图标为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/noti_icon"/>

基于问题此处

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

解决方案

您必须在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);
}

记住要自定义代码以支持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);
    }

When using Parse for push notifications our app always displayed the application's launcher icon. In the latest Android 5.1 version, the icon appears to be blank (a white square).

I tried setting the icon in the meta data:

<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/noti_icon"/>

Based on the question here

But nothing seems to work. Any ideas?

解决方案

You must use a transparent and white icon under Android Lollipop 5.0 or greater. You can extend ParsePushBroadcastReceiver class and override the two methods to get your notification icon compatible with these Android APIs.

    @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);
}

Remember to customize your code to support Lollipop and previous APIs.

        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);
    }

这篇关于Android 5.1推送通知图标为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆