shinyorg / shiny

.NET Framework for Backgrounding & Device Hardware Services (iOS, Android, & Catalyst)
https://shinylib.net
MIT License
1.43k stars 227 forks source link

[Bug]: Notification not clickable #1466

Closed IeuanWalker closed 4 months ago

IeuanWalker commented 4 months ago

Component/Nuget

Push - Native (Shiny.Push)

What operating system(s) are effected?

Version(s) of Operation Systems

Android 13

Hosting Model

Steps To Reproduce

When the device receives the notification, I tap on it -

I believe everything is set up correctly.

App

In the MauiProgram.cs -

// I initialise shiny
.UseShiny()

// Register my delegate and give it the default channel
builder.Services.AddPush<MyPushDelegate>(
#if ANDROID
    new FirebaseConfig(
        DefaultChannel: DefaultChannel()
    )
#endif
);

#if ANDROID
    static NotificationChannel? DefaultChannel()
    {
        if (OperatingSystem.IsAndroidVersionAtLeast(30))
        {
            return new NotificationChannel("default_channel", "Default Channel", NotificationImportance.Default)
            {
                LockscreenVisibility = NotificationVisibility.Public
            };
        }

        return null;
    }
#endif

MainActivity.cs, I've added the intent

[IntentFilter([Shiny.ShinyPushIntents.NotificationClickAction])]

AndroidManifest -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification" />
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</manifest>

Backend

In the backend I've set the ClickAction -

Message message = new()
{
    Notification = new Notification
    {
        Title = notification.Title,
        Body = notification.Message
    },
    Token = notification.Registration.FcmId,
    Data = data,
    Android = new AndroidConfig
    {
        Notification = new AndroidNotification
        {
            ClickAction = "SHINY_NOTIFICATION_CLICK"
        }
    },
};

notification.FcmId = await FirebaseMessaging.DefaultInstance.SendAsync(message);

Expected Behavior

When the notification is tapped on, it removes the notification from the list, launches the app, and triggers the OnEntry method

Actual Behavior

The notification remains in the notification list, the app never launches, and OnEntry is never triggered

Exception or Log output

No response

Code Sample

No response

Code of Conduct

aritchie commented 4 months ago

Please submit repros and do a little more digging before filing these.

SHINY_NOTIFICATION_CLICK is not correct https://shinylib.net/client/push/faq/

[IntentFilter([Shiny.ShinyPushIntents.NotificationClickAction])] is missing values https://shinylib.net/client/appbuilder/

IeuanWalker commented 4 months ago

Thanks @aritchie, working now.

SHINY_NOTIFICATION_CLICK is not correct

I copied this from the source code you linked earlier. It uses your the 'Shiny.Extensions.Push' Nuget, which in the src code sets the click action as SHINY_NOTIFICATION_CLICK - https://github.com/shinyorg/apiservices/blob/d960b92b9048cce8e7e4f54d869c405aecf3e29a/src/Shiny.Extensions.Push.GoogleFirebase/ShinyAndroidIntentEvents.cs#L6C4-L6C88

[IntentFilter([Shiny.ShinyPushIntents.NotificationClickAction])] is missing values

I had this setup originally based on the docs, but as it wasn't working, I looked at the src code of this repo and saw it was set up differently - https://github.com/shinyorg/shiny/blob/a5e6b62deb5801acac11cbf687784e9d264979d4/samples/Sample.Maui/Platforms/Android/MainActivity.cs#L17C1-L19C4