addVibration
Adds vibration to the notification.
Configures whether the device should vibrate when this notification is displayed. Vibration provides tactile feedback that a notification has arrived, useful when the device is in the user's pocket or on silent mode.
The vibration pattern is controlled by the VibrateType setting configured through PushwooshNotificationSettings. You can customize the vibration pattern globally or per notification.
Android 8.0+ Note: Vibration settings are controlled by notification channels and cannot be changed after the channel is created.
Permission Required: The app needs the VIBRATE permission in AndroidManifest.xml. Example - Enable vibration:
public Notification onGenerateNotification(@NonNull PushMessage data) {
String channelId = addChannel(data);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
getApplicationContext(), channelId)
.setContentTitle(data.getHeader())
.setContentText(data.getMessage())
.setSmallIcon(R.drawable.ic_notification);
Notification notification = builder.build();
// Enable vibration using push payload setting
addVibration(notification, data.getVibration());
return notification;
}
public Notification onGenerateNotification(@NonNull PushMessage data) {
String channelId = addChannel(data);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
getApplicationContext(), channelId)
.setContentTitle(data.getHeader())
.setContentText(data.getMessage())
.setSmallIcon(R.drawable.ic_notification);
Notification notification = builder.build();
// Only vibrate for high-priority notifications
boolean shouldVibrate = data.getPriority() >= NotificationCompat.PRIORITY_HIGH;
addVibration(notification, shouldVibrate);
return notification;
}
Parameters
The notification to add vibration to
true to enable vibration, false to disable