Android 未应用通知文本和样式

Android 未应用通知文本和样式,android,react-native,react-native-android,android-notifications,Android,React Native,React Native Android,Android Notifications,为了获取位置更新,我创建了一个前台服务。为此,我需要创建一个粘性通知,通知用户应用程序正在运行前台服务 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // Create intent and pending intent for the foreground service Intent notificationIntent = new Intent(this, MainActivity.clas

为了获取位置更新,我创建了一个前台服务。为此,我需要创建一个粘性通知,通知用户应用程序正在运行前台服务

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // Create intent and pending intent for the foreground service
        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        // Create notification channel
        this.geolocationNotification.createNotificationChannel();

        // Create the notification
        Notification.Builder builder = new Notification.Builder(this.getApplicationContext(), ChannelConstants.CHANNEL_ID)
                .setContentTitle(geolocationDTO.getTitle())
                .setContentText("geolocationDTO.getDescription()")
                .setContentIntent(pendingIntent);
        Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle();
        bigTextStyle.setBigContentTitle(geolocationDTO.getTitle());
        bigTextStyle.bigText(geolocationDTO.getDescription());
        builder.setStyle(bigTextStyle);
        Notification notification = builder.build();


        // Start the foreground service
        this.startForeground(NotificationConstants.NOTIFICATION_ID, notification);
    }
即使应用程序已关闭且正在创建通知,我也会获得位置更新,但是,无论是我传递的文本还是应用的样式,它都会显示默认文本:

  • contentTitle:“{appName}正在运行”
  • contentText:“点击以获取更多信息或停止应用程序。”
  • 另外,当我点击通知而不是打开应用程序,打开应用程序信息时,我尝试使用以下标志来更改此行为:Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK(如Android文档所述),但它不起作用