升级到Android O 版本后,该方法被以下方法取代:
NotificationCompat.Builder(Context context, String channelId)
即新增一个String参数即可,因此,简单notification可以直接加一个String参数:
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(this,"default") .setContentTitle("测试notification") .setContentText("This is content text") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher_round) .build(); manager.notify(1,notification);
NotificationCompat.Builder()过时,失效
原文:https://www.cnblogs.com/youkiii/p/14545436.html