in android/src/main/java/com/aliyun/ams/push/AliyunPushModule.java [448:554]
public void createChannel(ReadableMap params, Promise promise) {
WritableMap result = new WritableNativeMap();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String id = params.getString("id");
String name = params.getString("name");
int importance = params.getInt("importance");
String desc = params.getString("desc");
String groupId = null;
if (params.hasKey("groupId")) {
groupId = params.getString("groupId");
}
boolean allowBubbles = false;
if (params.hasKey("allowBubbles")) {
allowBubbles = params.getBoolean("allowBubbles");
}
boolean light = false;
if (params.hasKey("light")) {
light = params.getBoolean("light");
}
int color = -1;
if (params.hasKey("lightColor")) {
color = params.getInt("lightColor");
}
boolean showBadge = false;
if (params.hasKey("showBadge")) {
showBadge = params.getBoolean("showBadge");
}
String soundPath = null;
if (params.hasKey("soundPath")) {
soundPath = params.getString("soundPath");
}
int soundUsage = AudioAttributes.USAGE_UNKNOWN;
if (params.hasKey("soundUsage")) {
soundUsage = params.getInt("soundUsage");
}
int soundContentType = AudioAttributes.CONTENT_TYPE_UNKNOWN;
if (params.hasKey("soundContentType")) {
soundContentType = params.getInt("soundContentType");
}
int soundFlag = AudioAttributes.FLAG_LOW_LATENCY;
if (params.hasKey("soundFlag")) {
soundFlag = params.getInt("soundFlag");
}
boolean vibration = false;
if (params.hasKey("vibration")) {
vibration = params.getBoolean("vibration");
}
long[] vibrationPatterns = null;
if (params.hasKey("vibrationPattern")) {
ReadableArray readableArray = params.getArray("vibrationPattern");
if (readableArray != null) {
vibrationPatterns = new long[readableArray.size()];
if (readableArray.size() != 0) {
for (int i = 0; i < readableArray.size(); i++) {
double pattern = readableArray.getDouble(i);
vibrationPatterns[i] = Math.round(pattern);
}
}
}
}
NotificationManager notificationManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(id, name, importance);
channel.setDescription(desc);
if (groupId != null) {
channel.setGroup(groupId);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
channel.setAllowBubbles(allowBubbles);
}
channel.enableLights(light);
if (color != -1) {
channel.setLightColor(color);
}
channel.setShowBadge(showBadge);
if (!TextUtils.isEmpty(soundPath)) {
File file = new File(soundPath);
if (file.exists() && file.canRead() && file.isFile()) {
if (soundUsage < 0) {
channel.setSound(Uri.fromFile(file), null);
} else {
AudioAttributes.Builder builder = new AudioAttributes.Builder()
.setUsage(soundUsage);
builder.setContentType(soundContentType);
builder.setFlags(soundFlag);
channel.setSound(Uri.fromFile(file), builder.build());
}
}
}
channel.enableVibration(vibration);
if (vibrationPatterns != null && vibrationPatterns.length > 0) {
channel.setVibrationPattern(vibrationPatterns);
}
notificationManager.createNotificationChannel(channel);
result.putString(CODE_KEY, CODE_SUCCESS);
} else {
result.putString(CODE_KEY, CODE_NOT_SUPPORT);
result.putString(ERROR_MSG_KEY,
"Android version is below Android O which is not support create channel");
}
promise.resolve(result);
}