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 消息通知-Notification
  2. Android - 对话框(Dialog)和通知(Notification)2
  3. Android实现google消息通知
  4. android添加通知到顶部任务栏
  5. Android ble setCharactersticNotification() 依然无法收到通知
  6. Android通知工具类,含8.0通知适配,打开通知设置页面适配
  7. Android单击屏幕获得坐标,屏幕多点触摸测试器
  8. Android下的junit 单元测试

随机推荐

  1. Android系统定制源码修改 - MTK平台
  2. android中几种定位方式详解
  3. Android 连接USB 默认选中MTP
  4. Android4.0 设置系统默认输入法
  5. 页面跳转与传值(Activity跳转与传值)
  6. Android 和 PHP 之间进行数据加密传输
  7. Android的第一个程序运行
  8. 在Android中解析XML
  9. Android(安卓)2.3.x WebView中的两个搞笑
  10. Lottie-移动动画效果框架