Direct reply notification starts an activity

508 views Asked by At

I am trying to get the text typed on the direct reply. I can get the text but when click the send text button, it opens the activity that intent shows.

val resultIntent = Intent(this, MessagesActivity::class.java)
val stackBuilder = TaskStackBuilder.create(this)

stackBuilder.addNextIntent(resultIntent)

val resultPendingIntent = PendingIntent.getActivity(
        this,
        0,
        resultIntent,
        PendingIntent.FLAG_UPDATE_CURRENT
)

And here's Notification Builder

val mBuilder = Notification.Builder(this, id)
    .setContentTitle(data["title"])
    .setContentText(data["body"])
    .setLargeIcon(image)
    .addAction(action)
    .setSmallIcon(R.drawable.logo)
    .setAutoCancel(true)

I don't want it to open the activity. Also I tried to use a intent service, it does not work.

1

There are 1 answers

0
A. Shevchuk On BEST ANSWER

You are using PendingIntent.getActivity which means you want to handle result from your operation on activity. It's logical that this activity need to start before proceeding. From documentation of getActivity:

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

You need to use PendingIntent.getBroadcast.

For more information look here