Alternative way on how to change setLatestEventInfo in notification receiver

后端 未结 1 622
挽巷
挽巷 2021-01-16 10:57

Hi i got stock in this point wherein \"setLatesEventInfo\" has an error. i know that setLatestEventInfo doesnt run on API 23 and up. can someone help me on how to make this

相关标签:
1条回答
  • 2021-01-16 11:29

    Now you have to generate your notification like this

        NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    
        NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(context);
    
        // set intent so it does not start a new activity
        Notification notification  = builder
                .setContentIntent(yourPendingIntent)
                .setSmallIcon(icon)
                .setWhen( System.currentTimeMillis();)
                .setContentTitle(title)
                .setContentText(message).build();
    
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(notifId, notification);
    
    0 讨论(0)
提交回复
热议问题