Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation shortcut push not working #2302

Open
posth2071 opened this issue Apr 17, 2024 · 0 comments
Open

Conversation shortcut push not working #2302

posth2071 opened this issue Apr 17, 2024 · 0 comments

Comments

@posth2071
Copy link

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)
    

`
3. 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,
);

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant