android 通知 Notification
16lz
2021-12-04
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(安卓)TextView中android:textIsSelectable属性在Recycle
- Android通过图片名字获得ID
- Android(安卓)Service一前台服务(四)
- Android(安卓)Ant打包及其环境变量配置
- Android笔记之一:Hello, Android
- Android(安卓)多版本多渠道打包
- App应用之提交到各大市场渠道
- Android(安卓)setTheme设置透明主题无效
- Android(安卓)CheckBox中设置padding无效解决办法