如何使用Foreground应用程序实现Firebase云消息传递? [英] How to implement Firebase Cloud messaging with Foreground application?

查看:125
本文介绍了如何使用Foreground应用程序实现Firebase云消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在前台应用程序中接收活动中的消息,并使用Toast显示消息?我只在应用程序处于后台时收到通知。

How to receive a message in an Activity with the application in the foreground and display the message with Toast? I receive notification only when the app is in the background.

类似于实时消息。

请帮助我!!

Please help me !!

推荐答案

registerReceiver(new MyReceiver(),new IntentFilter("MyReceiver"));

然后在该Activity中创建一个MyReceiver BroadCastReceiver作为内部类。
as。

then create a MyReceiver BroadCastReceiver as the inner class in that Activity. as.

public class MyReceiver extends BroadCastReceiver{
    public void onReceive(Context context, Intent intent){
        Toast.makeText(context,intent.getStringExtra("from")+"         "+intent.getStringExtra("message"),Toast.LENGTH_SHORT).show();
    }

}
    ///finally you have to write the following codes on the 
    onMessageReceived
    Intent intents=new Intent();
    intents.setAction("MyReceiver");
    intents.putExtra("message",message.getData().get("message"));
    intents.putExtra("from",message.getData().get("from"));
    getBaseContext().sendBroadcast(intents);

这篇关于如何使用Foreground应用程序实现Firebase云消息传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆