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

ε祈祈猫儿з 提交于 2021-01-02 05:57:06

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/57957739/firebase-in-app-messaging-showing-in-splashactivity-how-to-show-it-in-mainactiv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!