Y. Vasquez Y. Vasquez - 1 year ago 188
Android Question

How to implement Firebase Cloud messaging with Foreground application?

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.

Something like messages in real time.

Please help me !!

Answer Source

On the oncreate method of activity to display toast.write.

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

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 
    Intent intents=new Intent();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download