Creating Custom Ringtones as Message Reminders
Background
Given the sheer number of apps out there, it’s important to make your own app stand out from the crowd. Custom ringtones are a good way to do that, for example, if you’ve developed a payment, online education, or video app. When a tone is played to indicate a message has been delivered, users will be able to identify your app in an instant, and develop a greater appreciation for it.
So, let’s move on to the process for creating custom ringtones in HUAWEI Push Kit to increase your message impressions.
Basic Ideas
Procedure
1. Set a ringtone for the service and communication messaging channel.
Restrictions: Make sure that the EMUI version is 9.1.0 or later and the Push Service app version is 9.1.1 or later.
To view the Push Service app version, go to Settings > Apps > Apps on your device, and search for Push Service.
1) Perform configuration on your app.
a. The ringtone to be used can only be stored in the /res/raw directory of the app.
b. Supported ringtone file formats are: MP3, WAV, and MPEG.
For example, store the bell.mp3 file in /res/raw.
2) Perform configuration on your app server.
a. Construct a common downlink message request. In the request:
b. Set importance to NORMAL, indicating that the message is a service and communication message.
c. Set default_sound to false, indicating that the value of sound is used.
d. Set sound to the path where the custom ringtone is stored on the app.
For example, for the bell.mp3 file on the app, set sound to /raw/bell.
3) Effects
4) FAQs
a. Q: Why can I only set the ringtone for the service and communication messaging channel?
A: For the other channel, that is, news and marketing messaging channel, the default message reminder mode is no lock screen, no ringtone, and no vibration. Therefore, the ringtone will not take effect even if it is set. For news and marketing messages, the user will need to set a ringtone.
b. Q: Why do I need to set the default ringtone before sending a message for the first time after the app is installed?
A: The ringtone is an attribute for the messaging channel. Therefore, the ringtone will only take effect after being set during the channel creation. Once the channel is created, the user will need to manually modify the messaging settings for a channel.
2. Set a ringtone for a custom messaging channel.
Restrictions: Make sure that the EMUI version is 10.0.0 or later and the Push Service app version is 10.0.0 or later.
1) Perform configuration on your app.
a. Save the ringtone file to the /assets or /res/raw directory.
For example, store the bell.mp3 file in /res/raw.
b. Create a messaging channel. (Note: The custom ringtone can only be set when the channel level is NotificationManager.IMPORTANCE_DEFAULT or higher.)
c. Set the ringtone.
For example, create the messaging channel “test” and set the channel ringtone to “/res/raw/bell.mp3”.
createNotificationChannel(“test”, “Channel 1”, NotificationManager.IMPORTANCE_DEFAULT);
2) Perform configuration on your app server.
a. Construct a common downlink message request. In the request:
b. Set importance to NORMAL, indicating that the message is a service and communication message.
c. Set channel_id to the ID of the channel created on the app, so that the message can be displayed on the channel.
For example, set channel_id to test.
3) Effects
4) FAQs
Q: Why do I need to set importance to NORMAL for the custom channel?
A: For the other channel, that is, news and marketing messaging channel, the default message reminder mode is no lock screen, no ringtone, and no vibration, which will minimize the distraction to users.
Precautions
1. The ringtone set by a user has the highest priority. If the user changes it to another ringtone, the new ringtone will prevail.
2. The following table lists the impact of each field in the downlink message on the ringtone (the intelligent classification is not considered).
To learn more, please visit:
>> HUAWEI Developers official website
>> Reddit to join developer discussions
>> GitHub or Gitee to download the demo and sample code
>> Stack Overflow to solve integration problems
Follow our official account for the latest HMS Core-related news and updates.