String myChannelId = "iot";                String myChannelName = "告警通知服务";                NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);                Notification notification = null;                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {                    NotificationChannel channel = new NotificationChannel(myChannelId, myChannelName,                            NotificationManager.IMPORTANCE_LOW);                    Toast.makeText(this, myChannelId, Toast.LENGTH_SHORT).show();                    manager.createNotificationChannel(channel);                    notification = new NotificationCompat.Builder(this, myChannelId)                            .setContentTitle("测试")                            .setContentText("一个新消息")                            .setWhen(System.currentTimeMillis())                            .setShowWhen(true)                            .setSmallIcon(R.mipmap.ic_launcher)                            .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))                            .build();                }else {                    notification = new NotificationCompat.Builder(this, myChannelId)                            .setContentTitle("This is a title")                            .setContentText("This is a context")                            .setWhen(System.currentTimeMillis())                            .setSmallIcon(R.mipmap.ic_launcher)                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))                            .build();                }                manager.notify(1, notification);

更多相关文章

  1. Android(安卓)模拟返回键功能
  2. Android(安卓)消息通知-Notification
  3. Android(安卓)- 对话框(Dialog)和通知(Notification)2
  4. android 8.0 service
  5. Android实现google消息通知
  6. Android单击屏幕获得坐标,屏幕多点触摸测试器
  7. android 4.0 cts
  8. Android:setLatestEventInfo问题
  9. Android(安卓)ble setCharactersticNotification() 依然无法收到

随机推荐

  1. Android官方DataBinding(三):RecyclerView
  2. Android常见错误处理
  3. Android Studio 导入 GreenDao
  4. 使用PHP开发Android应用程序技术介绍
  5. Android:Designing for Performance
  6. Android(一)Android Eclipse环境搭建
  7. Android_RelativeLayout属性大全
  8. Error:(1, 0) The android gradle plugin
  9. 使用AudioTrack播放PCM音频数据(android)
  10. android 过渡动画研究