Android 8.0和8.1通知栏

//如果版本大于8.0 创建渠道通知
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    String channelId = "defatle";
    String channeName = "xxxx";
    int importance = NotificationManager.IMPORTANCE_HIGH;
    createNotificationChannel(channelId, channeName, importance);
}

 

notification = new NotificationCompat.Builder(this, "defatle")
        .setSmallIcon(R.mipmap.mill_logo)
        .setContentTitle(bean.getName() + msg_num)
        .setContentText(msgtypestr)
        .setWhen(System.currentTimeMillis())
        .setDefaults(Notification.DEFAULT_VIBRATE)
        .build();

 

@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannel(String channelId, String channelName, int importance) {
    NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.createNotificationChannel(channel);
}

你可能感兴趣的:(Android)