Skip to content

Commit 1cb0879

Browse files
committed
feat(channel): add channel to notification "Your device is registered.”.
1 parent 7b63194 commit 1cb0879

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

AndroidSDK/src/com/leanplum/Leanplum.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -843,18 +843,38 @@ public void onResponse(boolean success) {
843843
@Override
844844
public void run() {
845845
try {
846-
NotificationCompat.Builder mBuilder =
847-
new NotificationCompat.Builder(currentContext)
848-
.setSmallIcon(android.R.drawable.star_on)
849-
.setContentTitle("Leanplum")
850-
.setContentText("Your device is registered.");
851-
mBuilder.setContentIntent(PendingIntent.getActivity(
846+
NotificationCompat.Builder builder = null;
847+
// If we are targeting API 26, try to post notification to default channel.
848+
if (LeanplumNotificationChannel.isNotificationChannelSupported(context)) {
849+
try {
850+
String channelId = LeanplumNotificationChannel.getDefaultNotificationChannelId(context);
851+
if (!TextUtils.isEmpty(channelId)) {
852+
builder = new NotificationCompat.Builder(context, channelId);
853+
} else {
854+
Log.w("Failed to post notification, there are no notification channels configured.");
855+
return;
856+
}
857+
} catch (Exception e) {
858+
Log.e("Failed to post notification, there are no notification channels configured.");
859+
}
860+
} else {
861+
builder = new NotificationCompat.Builder(context);
862+
}
863+
864+
if (builder == null) {
865+
return;
866+
}
867+
868+
builder.setSmallIcon(android.R.drawable.star_on)
869+
.setContentTitle("Leanplum")
870+
.setContentText("Your device is registered.");
871+
builder.setContentIntent(PendingIntent.getActivity(
852872
currentContext.getApplicationContext(), 0, new Intent(), 0));
853873
NotificationManager mNotificationManager =
854874
(NotificationManager) currentContext.getSystemService(
855875
Context.NOTIFICATION_SERVICE);
856876
// mId allows you to update the notification later on.
857-
mNotificationManager.notify(0, mBuilder.build());
877+
mNotificationManager.notify(0, builder.build());
858878
} catch (Throwable t) {
859879
Log.i("Device is registered.");
860880
}

AndroidSDK/src/com/leanplum/LeanplumPushService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private static void showNotification(Context context, Bundle message) {
372372
}
373373

374374
// Try to put notification on top of notification area.
375-
if (Build.VERSION.SDK_INT >= 16) {
375+
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 26) {
376376
builder.setPriority(Notification.PRIORITY_MAX);
377377
}
378378
builder.setAutoCancel(true);

0 commit comments

Comments
 (0)