deluxan
deluxan

Reputation: 422

Open an activity on notification receives

I am using FCM token for push notification. How can I open a specific activity while incoming call receives. For example I want to open IncomingActivity which contains "Accept" and "Decline" button. How can I open when message receives (not onclick)

I tried the following but not working

override fun onMessageReceived(remoteMessage: RemoteMessage) {
    super.onMessageReceived(remoteMessage)

    Log.i(TAG, remoteMessage.data.toString())

    val intent = Intent(this, VideoIncomingActivity::class.java)
    startActivity(intent)
}

Upvotes: 0

Views: 221

Answers (1)

Md Hanif
Md Hanif

Reputation: 1107

you should use broadcast receivers in such cases. You can follow this and this S.O Questions which has similar usecase as you have.

Although if you want to use your added code then you need to set Intent.FLAG_ACTIVITY_NEW_TASK flag to your intent and that should work as well.

But remember onMessageReceived is called only when the app is in foreground.

Upvotes: 1

Related Questions