in mpush_reactnative_android_demo/AwesomeProject/android/app/src/main/java/com/awesomeproject/MainApplication.java [72:94]
private void initNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 通知渠道的id。
String id = "1";
// 用户可以看到的通知渠道的名字。
CharSequence name = "notification channel";
// 用户可以看到的通知渠道的描述。
String description = "notification description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
// 配置通知渠道的属性。
mChannel.setDescription(description);
// 设置通知出现时的闪灯(如果Android设备支持的话)。
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
// 设置通知出现时的震动(如果Android设备支持的话)。
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
// 最后在notificationmanager中创建该通知渠道。
mNotificationManager.createNotificationChannel(mChannel);
}
}