drybnikov / klaviyo_flutter

BSD 3-Clause "New" or "Revised" License
4 stars 9 forks source link

android notification not shown #2

Closed Korpyc closed 1 year ago

Korpyc commented 1 year ago

Hi, I've investigated and communicated with Klaviyo support. They NOT send remote notification to the app, they send us data message, a bit same, but without Notification with title&body inside. But those fields exit in payload data.

They expect that we will process notification by next Kotlin code: KlaviyoNotification(message).displayNotification(this)

https://github.com/klaviyo/klaviyo-android-sdk

Could you please add this handling into library? Because if not, notification never will be in android system notifications center.

In addition, could you please explain purpose of it? is it your custom logging of push notification via Klaviyo events?

f (Klaviyo.isKlaviyoPush(metaData)) {
                    val event = Event(EventType.OPENED_PUSH, metaData.mapKeys {
                        EventKey.CUSTOM(it.key)
                    })
                    return try {
                        Klaviyo.getPushToken()?.let { event[EventKey.PUSH_TOKEN] = it }

                        Klaviyo.createEvent(event)
                        result.success(true)
                    } catch (e: Exception) {
                        Log.e(
                            TAG, "Failed handle push metaData:$metaData. Cause: $e"
                        )
                        result.error("Failed handle push metaData", e.message, null)
                    }
drybnikov commented 1 year ago

According to Klaviyo documentation, please add to AndroidManifest.xml

<service
   android:name="com.klaviyo.pushFcm.KlaviyoPushService"
   android:exported="false">
   <intent-filter>
       <action android:name="com.google.firebase.MESSAGING_EVENT" />
   </intent-filter>
</service>

to your Android application class

class YourApplication : FlutterApplication() {
    override fun onCreate() {
        super.onCreate()

        Klaviyo.initialize(KLAVIYO_PUBLIC_API_KEY, applicationContext)
        registerActivityLifecycleCallbacks(Klaviyo.lifecycleCallbacks)
    }
}

This lib handlePush method, just wrapper around Klaviyo Android SDK handlePush(intent: Intent?) but instead Intent it use data from Flutter