android 通知(android 8.0可用)
阿新 • • 發佈:2018-05-18
通知 bsp null uil build eat 正常 nag HA
final String CHANNEL_ID = "channel_id_1"; final String CHANNEL_NAME = "channel_name_1"; 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{ 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);
android 通知(android 8.0可用)