Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfmc-mobilepushsdk/5e499b52b6b79b1920d9d64d135ee8bc to your computer and use it in GitHub Desktop.
Save sfmc-mobilepushsdk/5e499b52b6b79b1920d9d64d135ee8bc to your computer and use it in GitHub Desktop.
MarketingCloudSdk.init((Context) this, MarketingCloudConfig.builder()
// Other configuration values
.setNotificationCustomizationOptions(
NotificationCustomizationOptions.create(R.drawable.ic_notification_icon,
new NotificationManager.NotificationLaunchIntentProvider() {
@Nullable @Override
public PendingIntent getNotificationPendingIntent(@NonNull Context context,
@NonNull NotificationMessage notificationMessage) {
int requestCode = new Random().nextInt();
String url = notificationMessage.url();
PendingIntent pendingIntent;
if (TextUtils.isEmpty(url)) {
pendingIntent = PendingIntent.getActivity(
context,
requestCode,
new Intent(context, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT
);
} else {
pendingIntent = PendingIntent.getActivity(
context,
requestCode,
new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
PendingIntent.FLAG_UPDATE_CURRENT
);
}
return pendingIntent;
}
}, new NotificationManager.NotificationChannelIdProvider() {
@NonNull @Override public String getNotificationChannelId(@NonNull Context context,
@NonNull NotificationMessage notificationMessage) {
if (TextUtils.isEmpty(notificationMessage.url())) {
return NotificationManager.createDefaultNotificationChannel(context);
} else {
return "UrlNotification";
}
}
}))
.build((Context) this), new MarketingCloudSdk.InitializationListener() {
@Override public void complete(@NonNull InitializationStatus status) {
// TODO handle initialization status
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment