Skip to content

Notification not rendering in app taskbar for background/terminated app #71

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

Closed
snghnishant opened this issue Oct 6, 2021 · 9 comments
Closed

Comments

@snghnishant
Copy link

snghnishant commented Oct 6, 2021

Flutter 2.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 02c026b03c (4 months ago) • 2021-05-27 12:24:44 -0700
Engine • revision 0fdb562ac8
Tools • Dart 2.13.1
firebase_messaging: ^10.0.0
clevertap_plugin: 1.3.0

@snghnishant
Copy link
Author

snghnishant commented Oct 6, 2021

Would like to know what does this CleverTapPlugin.createNotification(data) actually do and where it's needed to be invoked? It's very difficult to integrate your SDK without any proper documentation. Also, the documentation is a bit outdated as per the latest Cleveratap SDK integration available for flutter. So have created the issue for the same #72 .

@snghnishant
Copy link
Author

Update:- I am able to receive and handle the foreground message interaction after removing the createNotification method from the FCM foreground message handler, but having issues implementing background/terminated app notification.
After reading #46 and tried the mentioned solution I am able to receive the notification payload through the global FCM _firebaseMessagingBackgroundHandler which I am calling in the main.dart file but nothing happens afterwards. No notification UI is created in the app taskbar.

Code

// Initializing firebase background isolate
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // If you're going to use other Firebase services in the background, such as Firestore,
  // make sure you call `initializeApp` before using other Firebase services.
  await Firebase.initializeApp();
  CleverTapPlugin.createNotification(jsonEncode(message.data));
}

void main() async{
 // register fcm background handler handles message on terminate state
    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}

Logs

D/FLTFireMsgReceiver(31209): broadcast received for message
V/CleverTap:[:PushProvider:xxx-xxx-WK6Z](31209):  [PushType:FCM] received notification from CleverTap: Bundle[{wzrk_acct_id=TEST-xxx-xxx-WK6Z, nm=Background Notification testing, nt=Hello from CleverTap, wzrk_pivot=wzrk_default, wzrk_cid=, wzrk_rnv=true, wzrk_ttl=1634064603, wzrk_push_amp=false, wzrk_bc=, wzrk_bi=2, wzrk_ck=1630914817_1633978203, wzrk_dt=FIREBASE, wzrk_id=0_0, wzrk_pn=true}]
I/flutter (31209): inside createNotification Dart
D/CleverTapPlugin(31209): createNotification Android

@darshanclevertap
Copy link
Contributor

@snghnishant the createNotification method handles the rendering of the Push Notification with the payload sent from CleverTap servers. As per the logs, the method is being called. Are there more logs to help us understand why the payload is not rendering the desired Push notification?

@snghnishant snghnishant changed the title App crashing on calling CleverTapPlugin.createNotification(message.data) in Foreground message handling Unable to see notification in app taskbar for background and terminated app notification using CleverTapPlugin.createNotification(message.data) Oct 27, 2021
@snghnishant snghnishant changed the title Unable to see notification in app taskbar for background and terminated app notification using CleverTapPlugin.createNotification(message.data) Notification not rendering in app taskbar for background/terminated app Oct 27, 2021
@snghnishant
Copy link
Author

@snghnishant the createNotification method handles the rendering of the Push Notification with the payload sent from CleverTap servers. As per the logs, the method is being called. Are there more logs to help us understand why the payload is not rendering the desired Push notification?

No actually I only get this much log data even after the debug level is set to 3

@snghnishant
Copy link
Author

snghnishant commented Oct 27, 2021

I am adding some more info for your better understanding of the overall issues, maybe the issue could be with my SDK integration but that's what I can only do with limited documentation

// MainActivity.kt
package `in`.stratzy

import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity() {
}

Android Manifest

 <application
        android:name="com.clevertap.android.sdk.Application"
        android:label="Stratzy"
        android:icon="@mipmap/ic_launcher">
        <!-- Notification logo fix -->
        <!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_stat_stratzy" />
        <!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
             notification message. See README(https://goo.gl/6BKBk7) for more. -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorGreen" />
        <!-- [END fcm_default_icon] -->
        <!-- [START fcm_default_channel] -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id" />
        <!-- [END fcm_default_channel] -->
        <meta-data
            android:name="CLEVERTAP_ACCOUNT_ID"
            android:value="xxxxx-xxxxx-WK6Z"/>
        <meta-data
            android:name="CLEVERTAP_TOKEN"
            android:value="xxxxxxxx"/>
        <!-- IMPORTANT: To force use Google AD ID to uniquely identify  users, use the following meta tag. GDPR mandates that if you are using this tag, there is prominent disclousure to your end customer in their application. Read more about GDPR here - https://clevertap.com/blog/in-preparation-of-gdpr-compliance/ -->
        <meta-data
            android:name="CLEVERTAP_USE_GOOGLE_AD_ID"
            android:value="1"/>
        <!--Facebook analytics-->
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <!-- Deep linking -->
<!--            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />-->
<!--            <intent-filter android:autoVerify="true">-->
<!--                <action android:name="android.intent.action.VIEW" />-->
<!--                <category android:name="android.intent.category.DEFAULT" />-->
<!--                <category android:name="android.intent.category.BROWSABLE" />-->
<!--                <data android:scheme="http" android:host="stratzy.in" />-->
<!--                <data android:scheme="https" />-->
<!--            </intent-filter>-->
            <!-- Deep Links -->
            <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
              <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
              <data
                android:scheme="https"
                android:host="stratzy.page.link" />
            </intent-filter>
        </activity>
        <!-- Clevertap, read -https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTV4CHANGES.md -->
        <!-- to use Firebase messaging-->
        <service android:name="com.clevertap.android.sdk.pushnotification.fcm.FcmMessageListenerService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <!-- to enable push notification-->
        <service
            android:name="com.clevertap.android.sdk.pushnotification.CTNotificationIntentService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.clevertap.PUSH_EVENT" />
            </intent-filter>
        </service>
        <!--To enable Push Amplification-->
        <meta-data
            android:name="CLEVERTAP_BACKGROUND_SYNC"
            android:value="1"/>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>

@snghnishant
Copy link
Author

snghnishant commented Nov 15, 2021

@darshanclevertap quick update: now we are able to see the notification getting rendered in the system UI tray, you can close this issue. Thanks!

@darshanclevertap
Copy link
Contributor

@snghnishant Before I close the issue, can you share what you have done so that it can help our other users as well?

@snghnishant
Copy link
Author

@darshanclevertap Eventually It started working today when I tried pushing the notification from the CleverTap dashboard on my FCM token. No changes were made for this. I'll have my custom docs for CleverTap integration linked here with code later for handling the redirects in all three app state(Background, Terminated, Foreground) after testing it on iOS too.

@ducpn2111
Copy link

@snghnishant Did you have custom docs for CleverTap integration linked here with code later for handling the redirects in all three app state(Background, Terminated, Foreground) yet

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

3 participants