Last active
April 4, 2019 17:42
-
-
Save sfmc-mobilepushsdk/5e499b52b6b79b1920d9d64d135ee8bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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