android通知不能在5.0以后工作

时间:2015-10-23 14:41:37

标签: android notifications

尝试获取有关Android项目的通知,但似乎无法找出通知无效的原因?可能是我错过了某些东西,或者某些东西需要取出,但我无法弄明白。可能是这个项目在几年内没有被触及过。 任何帮助都会很棒! :)

private  void modifyNotification(String payload){       

        NotificationManager notificationManager = (NotificationManager) this.ctx
                .getSystemService(Context.NOTIFICATION_SERVICE);

        if(payload.equalsIgnoreCase(""))clearNotifications();
        else if(payload.equalsIgnoreCase("0"))clearNotifications();
        else{   


            Notification.Builder notificationBuilder = new Notification.Builder(this.ctx);
            notificationBuilder.setSmallIcon(R.drawable.icon);
            notificationBuilder.setNumber(R.string.notification_tray_text);//Unsure until tested
            notificationBuilder.setWhen(System.currentTimeMillis());


            Intent notificationIntent = new Intent(this.ctx, MainActivity.class);
            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this.ctx, 0, notificationIntent, 0);
            String notificationText = this.ctx.getString(R.string.notification_text);
            notificationText = String.format(notificationText, payload);
            notification.setLatestEventInfo(this.ctx, this.ctx.getString(R.string.notification_title), notificationText, pendingIntent);


            notification.number = Integer.parseInt(payload);

            notificationManager.notify(0, notification);
        }
    }

0 个答案:

没有答案