Set notification channels for Android 8.0
Background
For apps installed on Android 8.0 or later, you must create a notification channel. If you do not create a channel, the system silences all notifications and prevents them from appearing. When you send a push notification using the advanced OpenAPI, the value of the AndroidNotificationChannel parameter must match the channelId value from your app's code. If the values do not match, the notification will not appear.
Create a channel
You can specify the channel ID and whether the device vibrates or plays a sound. The following code shows an example.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // The ID of the notification channel. String channelId = "vibration_sound"; // This ID must be provided to backend developers and O&M engineers. It corresponds to the AndroidNotificationChannel parameter when a push notification is sent. // The user-visible name of the notification channel. CharSequence name = "My Test Channel"; // The user-visible description of the notification channel. String description = "My Test Channel"; int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = new NotificationChannel(channelId, name, importance); // Configure the properties of the notification channel. mChannel.setDescription(description); // Enable the notification light if the Android device supports it. mChannel.enableLights(true); mChannel.setLightColor(Color.RED); // Enable vibration if the Android device supports it. mChannel.enableVibration(true); // Custom ringtone mChannel.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.push_red_envelope), Notification.AUDIO_ATTRIBUTES_DEFAULT); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); // Create the notification channel in NotificationManager. mNotificationManager.createNotificationChannel(mChannel); }
Use the channel
After you create the channel in your app, save the `channelId` value. To ensure that server-side pushes are effective, match the channel ID as follows :
When you call the OpenAPI to send a push notification, set the AndroidNotificationChannel parameter to "vibration_sound". For more information, see Advanced Push API.
When you send push notifications from the EMAS console:
More information
You can call the code from the Create a channel section multiple times. This lets you create multiple channels for different purposes, such as 'sound only', 'vibration only', or 'sound and vibration'.
The `channelId` that you create in the Create a channel section is also used for the private message channel for self-classified messages on the OPPO manufacturer channel . For this purpose, you also use the `AndroidNotificationChannel` parameter.
Applies to
Mobile Push