private void showNotification2(Context context, int iid, String title, String text) {
String id = "my_channel_01";
String name = "我是渠道名字";
NotificationManager notificationManager = (NotificationManager) MyApplication.mContext.getSystemService(NOTIFICATION_SERVICE);
Notification notification = null;
Toast.makeText(this, "qweqweqwewqewq", Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(id, name, NotificationManager.IMPORTANCE_LOW);
Log.i("log", mChannel.toString());
notificationManager.createNotificationChannel(mChannel);
notification = new Notification.Builder(this)
.setChannelId(id)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher).build();
} else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(MyApplication.mContext)
.setContentTitle("5 new messages")
.setContentText("hahaha")
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true)
.setChannel(id);//无效
notification = notificationBuilder.build();
}
notificationManager.notify(iid, notification);
}
android 通知 Notification
最新推荐文章于 2021-02-20 15:15:35 发布
本文详细介绍了如何在Android系统中创建并显示通知,包括在不同API级别下的适配策略。展示了如何使用Notification和NotificationCompat.Builder来构建通知,以及如何创建NotificationChannel以适应Android Oreo及以上版本的要求。
5940

被折叠的 条评论
为什么被折叠?



