通知频道Android Oreo - 灯光颜色 - 默认值

时间:2017-10-13 06:59:26

标签: notifications channels android-8.0-oreo

我尝试在Android 8(Nexus 5x)上使用通知渠道而没有正面结果。通知附带默认值。我想改变灯光,振动等。有人使用API​​ 26的新通知通道系统(成功)吗? BTW导入来自v4支持lib,这是代码的主要部分:

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        String id = context.getString(R.string.app_name)+"_"+context.getString(R.string.notification);
        CharSequence name = getString(R.string.channel_name);
        String description = getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel mChannel = new NotificationChannel(id, name, importance);
        mChannel.setDescription(description);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.RED);
        mChannel.enableVibration(true);
        mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        mNotificationManager.createNotificationChannel(mChannel);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, id);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    mBuilder.setSmallIcon(R.drawable.ic_notification);
        mBuilder.setContentTitle(context.getString(R.string.app_name)+" - "+context.getString(R.string.reminder));
        mBuilder.setAutoCancel(true);
        mBuilder.setSound(alarmSound);
        //mBuilder.setVibrate(Utils.VIBRATION_3_1000);
        mBuilder.setColor(ContextCompat.getColor(context, R.color.primary));
mBuilder.setContentText(context.getString(R.string.reminder));
       // mBuilder.setLights(Color.MAGENTA, 1000, 500);
        mBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
        mBuilder.setContentIntent(resultPendingIntent);
        mNotificationManager.notify(1, mBuilder.build());

0 个答案:

没有答案