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读写锁
    正则表达式
    C++原型模式和模板模式
    C++外观模式和组合模式
    C++代理模式
    c++桥接模式
    Linux常用命令history/tcpdump/awk/grep
    C++委托模式
    c++ 读写锁
    布衣客
  • 原文地址:https://www.cnblogs.com/rchao/p/9057473.html
Copyright © 2011-2022 走看看