zoukankan      html  css  js  c++  java
  • android 通知(android 8.0可用)

     
    final String CHANNEL_ID = "com.chao.channel.id";
    final String CHANNEL_NAME = "com.chao.channel.name";
    
    NotificationManager mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification.Builder builder = null;
    
    
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
            builder = new Notification.Builder(this);
    }else{
    /**
     * Oreo不用Priority了,用importance
     * IMPORTANCE_NONE 关闭通知
     * IMPORTANCE_MIN 开启通知,不会弹出,但没有提示音,状态栏中无显示
     * IMPORTANCE_LOW 开启通知,不会弹出,不发出提示音,状态栏中显示
     * IMPORTANCE_DEFAULT 开启通知,不会弹出,发出提示音,状态栏中显示
     * IMPORTANCE_HIGH 开启通知,会弹出,发出提示音,状态栏中显示
     */过
      NotificationChannel notificationChannel = new 
      NotificationChannel(Config.CHANNEL_ID, Config.CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); //如果这里用IMPORTANCE_NOENE就需要在系统的设置里面开启渠道, //通知才能正常弹出  
      mManager.createNotificationChannel(notificationChannel);
      builder = new Notification.Builder(this,Config.CHANNEL_ID);
     } 
    notification = builder.build();
    mManager.notify(555, notification);

     部分机型使用IMPORTANCE_LOW MIN NONE仍然发出提示音问题,修改channelId,可以解决

  • 相关阅读:
    Linux 中 /proc/meminfo 的含义
    Linux OOM-killer(内存不足时kill高内存进程的策略)
    java反射
    IDEA 创建Web项目
    centos7 源码安装php7
    linux 基本原则和常用命令
    ls file less
    centos7安装nginx1.10.1
    mysqlworkbench访问远程服务器
    redis 简单的注册
  • 原文地址:https://www.cnblogs.com/rchao/p/9057473.html
Copyright © 2011-2022 走看看