ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
518 stars 583 forks source link

Support LocalNotifications setSummaryText for Android #218

Closed digaus closed 3 years ago

digaus commented 3 years ago

Feature Request

Plugin

LocalNotifications

Description

Support LocalNotifications setSummaryText for Android. Setting a summary is already possible for iOS. It should be added for Android when we set groupSummary to true.

Platform(s)

Android

Preferred Solution

Add summaryText to the LocalNotification object for Android

Alternatives

Reuse summaryArgument from iOS for this.

theproducer commented 3 years ago

I'm looking a bit deeper into this...

From the Android Docs for creating a group summary:

Notification summaryNotification =
    new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
        .setContentTitle(emailObject.getSummary())
        //set content text to support devices running API level < 24
        .setContentText("Two new messages")
        .setSmallIcon(R.drawable.ic_notify_summary_status)
        //build summary info into InboxStyle template
        .setStyle(new NotificationCompat.InboxStyle()
                .addLine("Alex Faarborg  Check this out")
                .addLine("Jeff Chang    Launch Party")
                .setBigContentTitle("2 new messages")
                .setSummaryText("janedoe@example.com"))
        //specify which group this notification belongs to
        .setGroup(GROUP_KEY_WORK_EMAIL)
        //set this notification as the summary for the group
        .setGroupSummary(true)
        .build();

It seems as if setting the "group summary" is the same as setting the content title / content text on a notification with setGroupSummary set as true.

const summaryNotification: LocalNotificationSchema = {
      id: 123,
      title: 'Summary of Notifications',
      body: 'Two new messages',
      group: "test-group",
      groupSummary: true,
};

Is there any particular reason you would need an explicit summaryText for this case?

digaus commented 3 years ago

@theproducer

In my tests (Android 11) when setting group summary the title and body of the group do not get shown.

Test as following:

const noti1 = {
            title: "Noti1",
            body: "Body1",
            id: 1,
            schedule: { at: new Date(Date.now() + 1000 * 5) },
            sound: null,
            attachments: null,
            actionTypeId: "",
            extra: null,
            group: '1',
        }
        const noti2 = {
            title: "Noti2",
            body: "Body2",
            id: 2,
            schedule: { at: new Date(Date.now() + 1000 * 5) },
            sound: null,
            attachments: null,
            actionTypeId: "",
            extra: null,
            group: '1',
        }
        const notiGroup: LocalNotification = {
            title: "NotiGroup",
            body: "NotiGroup",
            id: 3,
            schedule: { at: new Date(Date.now() + 1000 * 5) },
            sound: null,
            attachments: null,
            actionTypeId: "",
            extra: null,
            group: '1',
            groupSummary: true,
            summaryArgument: 'test',
        }
        const notifs = await LocalNotifications.schedule({
            notifications: [
                noti1,
                noti2,
                notiGroup,
            ]
          });

Left is without summary text and right is with summary text

inCollage_20210224_232738613

ionitron-bot[bot] commented 2 years ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.