hms-cordova-plugin
hms-cordova-plugin copied to clipboard
Create channel on cordova-plugin-hms-push
Description Hi i can´t find method for create channels for android, only have methods like:
getChannels() channelExists(): channelBlocked() deleteChannel()
Expected behavior Would exist method like createChannels
Current behavior Don´t exist, on definitions or documentation
Environment
- Platform: Cordova
- Kit: Push
- Kit Version all
- OS Version Android
- Android Studio version (if applicable): no
- Platform version any
- Node Version any
- Your Location/Region any
Other Would be very usefull to setup sound, color, etc...
You can create a channel when sending a local notification.
https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References/hms-local-notification-0000001057116694#section96612712551
Hi Xuejiao, i don't understand totally the workaround... Do you can share with me an example for create channel in localnotifications and next use that channel for push notifications on kill or close state of the app
You can refer to this link: https://github.com/HMS-Core/hms-cordova-plugin/blob/92caf01f43a3ff46ab80157073f1611d41d95685/cordova-plugin-hms-push/src/android/src/main/java/com/huawei/hms/cordova/push/local/HmsLocalNotificationController.java
The localNotificationNowPicture
function is used to send local notification, it will automatically create a new channel, and you do not need to call function to create the channel.
Then you can configure the attributes of the local notification by referring to the preceding method. The system automatically creates a specified channel and uses the channel to send push notifications.
So i next can send the channel_id on push json object to hms?
Do you have an example?
I have been searching on Huawei documentation and internet but i haven't successs using custom sound, for that i need channels.
PD. I already set successfully icon ando color for notification but no sound
Hello @halie412,
The ringtone file must be stored in the /res/raw directory under android/app/src/main folder of your app, for example, /res/raw/huawei_bounce.mp3
You can set your custom sound with [HmsLocalNotification.Attr.soundName]. You can use the example below.
HmsLocalNotification.localNotification({
...defaultNotification,
[HmsLocalNotification.Attr.title]: titleText,
[HmsLocalNotification.Attr.message]: messageText,
[HmsLocalNotification.Attr.bigText]: bigText,
[HmsLocalNotification.Attr.subText]: subText,
[HmsLocalNotification.Attr.tag]: tagText,
[HmsLocalNotification.Attr.playSound]: true,
[HmsLocalNotification.Attr.soundName]: "huawei_bounce.mp3",
})
.then((result) =>
defaultSuccessHandler("localNotification-Sound", result)
)
.catch((error) =>
defaultExceptionHandler("localNotification-Sound", error)
);
İf you want to set custom channel_id, You can set it with [HmsLocalNotification.Attr.channelId] parameter. You can use the example below.
const defaultNotification = {
[HmsLocalNotification.Attr.title]: "Notification Title",
[HmsLocalNotification.Attr.message]: "Notification Message", // (required)
[HmsLocalNotification.Attr.ticker]: "Optional Ticker",
[HmsLocalNotification.Attr.showWhen]: true,
// [HmsLocalNotification.Attr.largeIconUrl]: 'https://developer.huawei.com/Enexport/sites/default/images/en/Develop/hms/push/push2-tuidedao.png',
[HmsLocalNotification.Attr.largeIcon]: "ic_launcher",
[HmsLocalNotification.Attr.smallIcon]: "ic_notification",
[HmsLocalNotification.Attr.bigText]: "This is a bigText",
[HmsLocalNotification.Attr.subText]: "This is a subText",
[HmsLocalNotification.Attr.color]: "white",
[HmsLocalNotification.Attr.vibrate]: false,
[HmsLocalNotification.Attr.vibrateDuration]: 1000,
[HmsLocalNotification.Attr.tag]: "hms_tag",
[HmsLocalNotification.Attr.groupSummary]: false,
[HmsLocalNotification.Attr.ongoing]: false,
[HmsLocalNotification.Attr.importance]: HmsLocalNotification.Importance.MAX,
[HmsLocalNotification.Attr.dontNotifyInForeground]: false,
[HmsLocalNotification.Attr.autoCancel]: false,
[HmsLocalNotification.Attr.actions]: '["Yes", "No"]',
[HmsLocalNotification.Attr.invokeApp]: true,
[HmsLocalNotification.Attr.channelId]: 'huawei-hms-cordova-push-channel-id', // You can set custom channelid with this parametre
};
For more information about Huawei Cordova Push, you can access its official documentation via this link.