在android marshmallow和棒棒糖中推送通知问题

5 android push-notification

我尝试推送通知它在Android JellyBean中正常工作,但相同的代码不工作marshmallow和棒棒糖.

设备获取其他应用程序通知,如whatsapp,gmail ..也不能说设置问题.

谷歌搜索它的一些图标更改新版本,但我也没有收到通知,谢谢你们:)

我的通知代码:

 NotificationIntent = new Intent(this, Activity.class);
        NotificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

        NotificationPendingIntent = PendingIntent.getActivity(this, 0, NotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationBuilder = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("GREEK NEWS")
                .setContentText(content)
                .setDefaults(Notification.DEFAULT_ALL)
                .setAutoCancel(true)
                .setContentIntent(NotificationPendingIntent);

        NotificationManager = (android.app.NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            NotificationManager.notify(86, NotificationBuilder.build());
        } else {
            NotificationManager.notify(86, NotificationBuilder.getNotification());
        }
Run Code Online (Sandbox Code Playgroud)

Ngu*_*iếu 0

尝试更改通知图标

.setSmallIcon(getNotificationIcon())
Run Code Online (Sandbox Code Playgroud)

并创建方法

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.notification_icon : R.mipmap.ic_launcher;
}
Run Code Online (Sandbox Code Playgroud)

希望。对你有帮助!!!