Skip to content

Commit

Permalink
Merge pull request #672 from Microsoft/fix/notification-big-text
Browse files Browse the repository at this point in the history
Fix notification message being truncated
  • Loading branch information
dhei authored May 9, 2018
2 parents 832039c + fe97679 commit 0130659
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ static void handleNotification(Context context, Intent pushIntent) throws Runtim
builder.setContentTitle(notificationTitle).
setContentText(notificationMessage).
setWhen(System.currentTimeMillis());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
builder.setStyle(new Notification.BigTextStyle().bigText(notificationMessage));
}

/* Click action. Reuse notification id for simplicity. */
PendingIntent contentIntent = PendingIntent.getActivity(context, notificationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -102,6 +103,9 @@ public void setUp() throws Exception {
when(mNotificationBuilderMock.setWhen(anyLong())).thenReturn(mNotificationBuilderMock);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
when(mNotificationBuilderMock.build()).thenReturn(mNotificationMock);
Notification.BigTextStyle bigTextStyle = mock(Notification.BigTextStyle.class);
whenNew(Notification.BigTextStyle.class).withAnyArguments().thenReturn(bigTextStyle);
when(bigTextStyle.bigText(any(CharSequence.class))).thenReturn(bigTextStyle);
}
when(mNotificationBuilderMock.getNotification()).thenReturn(mNotificationMock);
whenNew(Notification.Builder.class).withArguments(mContextMock).thenReturn(mNotificationBuilderMock);
Expand Down Expand Up @@ -152,6 +156,11 @@ public void handlePushJellybean() throws Exception {
verify(mNotificationManagerMock).notify(anyInt(), any(Notification.class));
verifyStatic();
PushIntentUtils.setMessageId(eq(mDummyGoogleMessageId), same(mActionIntentMock));

/* Verify we apply big text style on Android 4.1+. */
ArgumentCaptor<Notification.BigTextStyle> styleArgumentCaptor = ArgumentCaptor.forClass(Notification.BigTextStyle.class);
verify(mNotificationBuilderMock).setStyle(styleArgumentCaptor.capture());
verify(styleArgumentCaptor.getValue()).bigText("message");
}

@Test
Expand Down

0 comments on commit 0130659

Please sign in to comment.