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.

Ashish
  • 6,791
  • 3
  • 26
  • 48
Shubham Pandey
  • 173
  • 1
  • 8

3 Answers3

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

Burak Dizlek
  • 4,805
  • 2
  • 23
  • 19
  • 1
    FirebaseInAppMessaging.getInstance().triggerEvent("main_activity_ready") worked for me – Jose Q Apr 15 '20 at 12:56
  • I would prefer: FirebaseInAppMessaging.getInstance().triggerEvent("main_activity_ready"), but under the hood and according to documentation it is the same thing. https://firebase.google.com/docs/in-app-messaging/modify-message-behavior?authuser=0&platform=android – I.Step Dec 07 '21 at 17:21
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
Zia
  • 1,204
  • 1
  • 11
  • 25
-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.

  • 2
    This answer not helps anyhow, what the reason to post it? The architecture of In-App messaing fully different GCM... – Hospes Mar 02 '20 at 10:50