android studio kotlin notification body click

Hakeem.D

Not sure how to open MainActivity when the body of notification is clicked:

class Notification : BroadcastReceiver()
{
    override fun onReceive(context: Context, intent: Intent)
    {
        val notification = NotificationCompat.Builder(context, channelID)
            .setSmallIcon(R.drawable.icon_notif_white)
            .setContentTitle(intent.getStringExtra(titleExtra))
            .setContentText(intent.getStringExtra(messageExtra))
            .build()

        val  manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        manager.notify(notificationID, notification)
    }

}
0awawa0

You need to add setContentIntent with pending intent for the MainActivity:

class Notification : BroadcastReceiver()
{
    override fun onReceive(context: Context, intent: Intent)
    {
        val activityIntent = Intent(context, MainActivity::class.java)
        val id = 0
        val pendingIntent = PendingIntent.getActivity(context, id, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT)

        val notification = NotificationCompat.Builder(context, channelID)
            .setSmallIcon(R.drawable.icon_notif_white)
            .setContentTitle(intent.getStringExtra(titleExtra))
            .setContentText(intent.getStringExtra(messageExtra))
            .setContentIntent(pendingIntent)
            .build()

        val  manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        manager.notify(notificationID, notification)
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change TextView text on button click in Android Studio ( Kotlin)

Toggle hidden & visable text on button click - Kotlin Android Studio

Notification Not Showing In Android Studio

Notification is not working(Android Studio)

Kotlin android app is not showing notification

Android Notification not closing on AddAction click

PendingIntent.getBroadcast not working on for the default notification click/touch event in the notifications drawer - Android Studio 2.3.3 + Java

Remove notification bar android studio

push Notification is not working in android studio

Kotlin in android studio

Android Studio Kotlin DatePicker

Right click in Android Studio

Multiple notification click launching a same activity android

Open activity after FCM notification click in Android

Click on notification to enter my app in android

Multiple notification wrong content on click android

How to open a browser on notification click in Android?

Android call notification - Stop timer when click

MvvmCross Navigate to ViewModel on Android notification click

Android- Firebase push notification click event

FCM Android - On click Notification - Open webview

How to build a notification in android and implement click listener?

Android: Detect status bar notification click

How to change activity image and text according to listview item click in android studio ? java or kotlin

Open activity after click in notification in alarmmanager and broadcast Kotlin

Android studio notification with alarm manager and broadcastreceiver not posting notification

Can FCM notification use `plurals` on Android for localizable title or body?

How to show a notification icon in android studio

Will unbindService clean Notification icon automatically in Android Studio?