PushwooshNotificationFactory
Default implementation of NotificationFactory provided by the Pushwoosh SDK.
This class serves as the reference implementation for creating push notifications with standard Pushwoosh features. It demonstrates best practices for building notifications and handling all notification data from the push payload, including rich media, actions, channels, and notification customization options.
Use this class as a starting point when creating your own custom notification factory. You can extend it and override specific methods to customize particular aspects while keeping the rest of the default behavior.
Features Implemented:
- Large icon loading from URLs
- Big picture style notifications with image loading
- Notification channels (Android 8.0+)
- Custom colors, priorities, and visibility settings
- Notification actions from push payload
- Sound, vibration, and LED from push payload
- HTML formatted text support
- Group notifications support (Android 7.0+)
Quick Start - Use as reference:
// This is the default factory - no registration needed
// Pushwoosh uses this automatically if no custom factory is specified
// To see how it works, look at onGenerateNotification() method
Content copied to clipboard
Example - Extend for customization:
public class MyNotificationFactory extends PushwooshNotificationFactory {
public Notification onGenerateNotification(@NonNull PushMessage data) {
// Call parent to get default notification
Notification notification = super.onGenerateNotification(data);
if (notification != null) {
// Add custom modifications
notification.flags |= Notification.FLAG_INSISTENT; // Keep alerting
}
return notification;
}
protected Bitmap getLargeIcon(PushMessage pushData) {
// Use custom image loading library
String iconUrl = pushData.getLargeIconUrl();
if (iconUrl != null) {
return MyImageLoader.loadSync(iconUrl);
}
return super.getLargeIcon(pushData);
}
}
// Register in AndroidManifest.xml:
<meta-data
android:name="com.pushwoosh.notification_factory"
android:value=".MyNotificationFactory" />
Content copied to clipboard
Example - Override for complete custom behavior:
public class MyNotificationFactory extends PushwooshNotificationFactory {
public Notification onGenerateNotification(@NonNull PushMessage data) {
// Don't call super - build completely custom notification
String channelId = addChannel(data);
NotificationCompat.Builder builder = new NotificationCompat.Builder(
getApplicationContext(), channelId)
.setContentTitle(data.getHeader())
.setContentText(data.getMessage())
.setSmallIcon(R.drawable.custom_icon)
.setColor(0xFF6200EE);
Notification notification = builder.build();
addCancel(notification);
return notification;
}
}
Content copied to clipboard
See also
Functions
Link copied to clipboard
Creates a notification channel for the push message if it doesn't already exist.
Link copied to clipboard
Adds vibration to the notification.
Link copied to clipboard
Provides a description for a notification channel.
Link copied to clipboard
Customizes the display name of a notification channel.
Link copied to clipboard
Loads and returns the big picture image for expanded notification style.
Link copied to clipboard
Converts HTML-formatted string to styled CharSequence for display in notifications.
Link copied to clipboard
Loads and returns the large icon image for the notification.
Link copied to clipboard
Creates the intent that will be fired when the user taps the notification.
Link copied to clipboard
Creates and configures a notification from push message data.