Fixed: Do not add BigTextStyle to notification if big text is null

It may cause a `NullPointerException` on Android `6`.

```
java.lang.RuntimeException: Unable to create service com.termux.app.TermuxService: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
  at android.app.ActivityThread.handleCreateService(ActivityThread.java:3048)
  at android.app.ActivityThread.access$2000(ActivityThread.java:156)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5609)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
  at android.app.Notification$Builder.processLegacyText(Notification.java:3217)
  at android.app.Notification$Builder.access$1100(Notification.java:2009)
  at android.app.Notification$BigTextStyle.makeBigContentView(Notification.java:4283)
  at android.app.Notification$BigTextStyle.populateBigContentView(Notification.java:4321)
  at android.app.Notification$Style.buildStyled(Notification.java:3858)
  at android.app.Notification$Builder.build(Notification.java:3661)
  at com.termux.app.TermuxService.buildNotification(TermuxService.java:841)
  at com.termux.app.TermuxService.runStartForeground(TermuxService.java:206)
  at com.termux.app.TermuxService.onCreate(TermuxService.java:120)
  at android.app.ActivityThread.handleCreateService(ActivityThread.java:3038)
  ... 8 more
```

- https://cs.android.com/android/platform/superproject/+/android-6.0.1_r1:frameworks/base/core/java/android/app/Notification.java;l=4135

Closes termux/termux-app#5113
This commit is contained in:
agnostic-apollo
2026-05-13 02:57:05 +05:00
parent 30ebb2dee3
commit 401bbe54b8

View File

@@ -71,7 +71,9 @@ public class NotificationUtils {
Notification.Builder builder = new Notification.Builder(context);
builder.setContentTitle(title);
builder.setContentText(notificationText);
builder.setStyle(new Notification.BigTextStyle().bigText(notificationBigText));
if (notificationBigText != null) {
builder.setStyle(new Notification.BigTextStyle().bigText(notificationBigText));
}
builder.setContentIntent(contentIntent);
builder.setDeleteIntent(deleteIntent);