Skip to content

Commit

Permalink
allow developers to customize the foreground notification text
Browse files Browse the repository at this point in the history
  • Loading branch information
mmartin101 committed Jun 10, 2018
1 parent c01abf3 commit 281b60d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,31 @@ void detach(Activity activity) {
}

private Notification createNotification(Activity activity) {
return new NotificationCompat.Builder(this, CHANNEL_ID)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentIntent(createContentPendingIntent())
.setSubText(getString(R.string.hype_notification_subtext))
.setTicker("")
.setSmallIcon(R.drawable.hype_logo)
.setOngoing(true)
.setVibrate(new long[] { 0 })
.build();
.setVibrate(new long[]{0});

String contentTitle = getString(R.string.hype_notification_content_title);
String contentText = getString(R.string.hype_notification_content_text);
String subText = getString(R.string.hype_notification_subtext);

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
builder.setContentTitle(contentTitle);
builder.setContentText(contentText.isEmpty() ? subText : contentText);
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
builder.setContentTitle(contentTitle);
builder.setContentText(contentText);
builder.setSubText(subText);
} else {
builder.setContentTitle(contentTitle.isEmpty() ? null : contentTitle);
builder.setContentText(contentText.isEmpty() ? null : contentText);
builder.setSubText(subText);
}

return builder.build();
}

private PendingIntent createContentPendingIntent() {
Expand Down
2 changes: 2 additions & 0 deletions hyperion-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>
<public name="hype_core" type="string">Hyperion Core</public>
<string name="hype_plugin_load_failure">Failed to load plugins.\\n%s</string>
<string name="hype_notification_content_title">Hyperion</string>
<string name="hype_notification_content_text"></string>
<string name="hype_notification_subtext">Tap to open the menu.</string>
<string name="hype_notification_action_open_drawer">Open Menu</string>
<string name="hype_notification_channel_name">Hyperion Foreground Notification</string>
Expand Down

0 comments on commit 281b60d

Please sign in to comment.