Firebase In-App Messaging showing in SplashActivity. How to show it in MainActivity?
Asked Answered
S

3

14

I have enabled Firebase In-App messaging for my android app. When i am testing In-App Messaging it is showing in SplashActivity of the app.

Activity flows like: SplashActivity>LoginActivity>MainActivity

Note: SplashActivity just have runnable to get delay of 3 seconds. LoginActivity have some functions to check wheter shared preferences are not null.

I tried to add in onCreate() this below line of code: FirebaseInAppMessaging.getInstance().setMessagesSuppressed(true)

And FirebaseInAppMessaging.getInstance().setMessagesSuppressed(false) in onDestroy()

I want this messsage to show in MainActivity.

Swamper answered 16/9, 2019 at 13:17 Comment(3)
I'm facing same problem. Did you solve this?Sacrificial
@Sacrificial Solved that ?Medicament
I've posted question with the same issue on github issue tracker. Maybe somebody will answer on it from devs. github.com/firebase/firebase-android-sdk/issues/1299 Please upvote it or subscribe to watch the responsesGasify
L
10

Firebase in-app messaging is triggered by analytical events.

if you want show message in MainActivity ->

class MainActivity : AppCompatActivity() { 
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...
    FirebaseAnalytics.getInstance(this).logEvent("main_activity_ready",null)
    //or 
    //FirebaseInAppMessaging.getInstance().triggerEvent("main_activity_ready");

}
}

and select this event in firebase console.

enter image description here

Ledezma answered 25/3, 2020 at 8:16 Comment(2)
FirebaseInAppMessaging.getInstance().triggerEvent("main_activity_ready") worked for meTeheran
I would prefer: FirebaseInAppMessaging.getInstance().triggerEvent("main_activity_ready"), but under the hood and according to documentation it is the same thing. firebase.google.com/docs/in-app-messaging/…Scissure
A
1

Use below method to "Start" and "Stop" InAppMessaging in different Activities.

public static void inAppMessagingInitialization(Context context, boolean setSuppressed,String eventName){ //setSuppressed false means start getting message
    FirebaseInAppMessaging.getInstance().setMessagesSuppressed(setSuppressed); //true==Stop inAppMessaging

    if (!eventName.equals("")){
        FirebaseAnalytics.getInstance(context).logEvent(eventName,null); //To Show InAppMessage in MainActivity. Need to add this event name in Web console campaign
        FirebaseInAppMessaging.getInstance().triggerEvent(eventName);
    }
}

If you don't want show in SplashActivity, then call above method like below:

inAppMessagingInitialization(context,true,""); //Stops inAppMessaging

To show InAppMessage in MainActivity call above method like below and set event name in InAppMessaging console.

inAppMessagingInitialization(context,false,"main_activity_inappmessaging"); //Starts inAppMessaging
Aegean answered 11/5, 2021 at 10:30 Comment(0)
P
-3

I just ran into this as I also have a launcher activity that has been reaping my notifications. I am going to assume that you set your splash activity to be your LAUNCHER:

        <activity android:name=".SplashActivity"
          android:theme="@style/SplashTheme">
          <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
        </activity>

The challenge is that the system delivers all the notifications to your LAUNCHER activity where they wait as Intent bundled data.

This is a significant topic on this threadHow to handle notification when app in background in Firebase, a key point of which is highlighted below:

  • App is in background: the notification is sent to the notification tray automatically by FCM. When the user touches the notification the app is brought to the foreground by launching the activity that has android.intent.category.LAUNCHER in the manifest.

Read through the entire linked thread as this is an area that appears to have been evolving lately.

Playlet answered 20/11, 2019 at 4:15 Comment(1)
This answer not helps anyhow, what the reason to post it? The architecture of In-App messaing fully different GCM...Gasify

© 2022 - 2024 — McMap. All rights reserved.