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
最新推荐文章于 2023-08-02 21:21:48 发布