安卓8.0通知样例

 String channelId = "1";
            String channelName = "channel_name";
            NotificationChannel channel = new NotificationChannel(channelId,channelName,NotificationManager.IMPORTANCE_HIGH);

            NotificationManager manager = (NotificationManager)this.getSystemService(this.NOTIFICATION_SERVICE);
            manager.createNotificationChannel(channel);
            Notification notification = new NotificationCompat.Builder(this)
                    .setTicker(resources.getString(R.string.new_pictures_title))
                    .setSmallIcon(android.R.drawable.ic_menu_report_image)
                    .setContentTitle(resources.getString(R.string.new_pictures_title))
                    .setContentText(resources.getString(R.string.new_pictures_text))
                    .setChannelId(channelId)
                    .setContentIntent(pi)
                    .setAutoCancel(true)
                    .build();
          //  NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
            manager.notify(0,notification);
发布了25 篇原创文章 · 获赞 1 · 访问量 7526

猜你喜欢

转载自blog.csdn.net/qq_28334237/article/details/89010737