bhandaribhumin / cordova-plugin-local-notification-12

Apache License 2.0
17 stars 35 forks source link

Notification makes a sound but does not show any text #7

Open jondspa opened 1 year ago

jondspa commented 1 year ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Android - Notification is triggered. Device makes a sound. I can see the notification text in the notification center. But no the notification text does not show on the screen.

I've been using this great plugin for a while, trying to update to SDK API 31. Have also tried API 32.

Your Environment

Expected Behavior

Notification text should appear on the screen as it always has done.

Actual Behavior

No notification text appears.

Here's my triggering code, which has not changed.

                    channel: "channel1",
                    id: 100 + m,
                    text: String(reminders[n][0]),
                    priority: 2,
                    foreground: true,

                    trigger: {
                        every: {
                            weekday: Number(reminders[n][1][n1]) + 1, // days 1-7
                            hour: Number(reminders[n][2][0]),
                            minute: Number(reminders[n][2][1])
                        },
                        count: 1
                    }

Context

Debug logs

Many, many thanks! Jon

jondspa commented 1 year ago

Figured it out.

Similar to the suggestion on this thread: https://github.com/katzer/cordova-plugin-local-notifications/issues/1589

I had to modify buildChannelWithOptions() to force importance=IMPORTANCE_HIGH in Manager.java.

public String buildChannelWithOptions(Uri soundUri, boolean shouldVibrate, boolean hasSound, CharSequence channelName, String channelId) { String defaultChannelId, newChannelId; CharSequence defaultChannelName; int importance;

    if (hasSound && shouldVibrate) {
        defaultChannelId = Options.SOUND_VIBRATE_CHANNEL_ID;
        defaultChannelName = Options.SOUND_VIBRATE_CHANNEL_NAME;
        importance = IMPORTANCE_HIGH;
        shouldVibrate = true;
    } else if (hasSound) {
        defaultChannelId = Options.SOUND_CHANNEL_ID;
        defaultChannelName = Options.SOUND_CHANNEL_NAME;
        importance = IMPORTANCE_DEFAULT;
        shouldVibrate = false;
    } else if (shouldVibrate) {
        defaultChannelId = Options.VIBRATE_CHANNEL_ID;
        defaultChannelName = Options.VIBRATE_CHANNEL_NAME;
        importance = IMPORTANCE_LOW;
        shouldVibrate = true;
    } else {
        defaultChannelId = Options.SILENT_CHANNEL_ID;
        defaultChannelName = Options.SILENT_CHANNEL_NAME;
        importance = IMPORTANCE_LOW;
        shouldVibrate = false;
    }

    newChannelId = channelId != null ? channelId : defaultChannelId;

    // newly added, force importance to be high
    importance = IMPORTANCE_HIGH;

    createChannel(newChannelId, channelName != null ? channelName : defaultChannelName, importance, shouldVibrate,
            soundUri);

    return newChannelId;
}