MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.45k stars 1.39k forks source link

Conversation shortcut push not working #2302

Closed posth2071 closed 1 week ago

posth2071 commented 5 months ago

I wanted the push to show up like the default messenger and other chat apps, so while working on it I looked for the keyword android conversation shortcut and tried to incorporate it.

In the native android code, when you open a notification via NotificationManager, in order to display it in the conversation style, it only needs to meet two conditions to be displayed correctly

1) set shortcutId 2) Set MessagingStyle

However, when displaying a push via FlutterLocalNotifications plugin, it is displayed in normal push style even if you apply two conditions

KakaoTalk_Photo_2024-04-17-11-24-32

The top notification in the attached photo shows the notification displayed via android native

The bottom notificationd is a notification displayed via FlutterLocalNotification

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ I'll attach my code

  1. Android Native code

    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    
    val channelName = "Channel human readable title"
    val channelDescription = "Channel human readable description"
    val importance = NotificationManager.IMPORTANCE_DEFAULT
    
    val channel = NotificationChannel(channelId, channelName, importance).apply {
        description = channelDescription
    }
    
    notificationManager.createNotificationChannel(channel)
    
    val notification = Notification.Builder(context, channelId)
        .setStyle(
            Notification.MessagingStyle(person)
                .addMessage("message 1", System.currentTimeMillis(), person)
                .addMessage("message 2", System.currentTimeMillis(), person)
                .addMessage("message 3", System.currentTimeMillis(), person)
        )
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("ContentTitle")
        .setContentText("ContentText")
        .setAutoCancel(true)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setShortcutId(shortcutId)
        .setContentIntent(
            PendingIntent.getActivity(
                context,
                0,
                Intent(context, MainActivity::class.java),
                PendingIntent.FLAG_IMMUTABLE
            )
        )
        .build()
    
    notificationManager.notify(1, notification)

    `

  2. Flutter LocalNotification code

    const shortcutId = 'shortcutId'; const person = Person( name: 'Person Name', icon: FlutterBitmapAssetAndroidIcon( 'assets/image/img_profile_placeholder.png'), );

    return _flutterLocalNotifications.show( 0, title, body, NotificationDetails( android: AndroidNotificationDetails( _channel.id, _channel.name, channelDescription: _channel.description, importance: Importance.max, priority: Priority.high, icon: _androidIcon, enableLights: true, styleInformation: MessagingStyleInformation( person, conversationTitle: shortcutId, messages: [ Message( 'local Message Text', DateTime.now(), person, ), ], ), shortcutId: shortcutId, ), iOS: const DarwinNotificationDetails( presentAlert: true, presentSound: true, presentBadge: true, ), ), payload: payload != null ? jsonEncode(payload.toJson()) : null, ); `

MaikuB commented 3 months ago

From what I can see, the two examples you've given aren't a direct comparison as the one with this plugin only has a single message there. Have you checked the example app? If you still believe there's an issue and want to provide examples then please provide links to repositories hosting minimal apps where they try to reproduce the exact same scenario using native Android code vs this plugin