Skip to content Skip to sidebar Skip to footer

Can Not Connect Button Click Action Intent In Main Activity To A Pending Intent In Service Class To Get Action In Notification Using .getaction()

I am trying to connect following MainActivity.java's buttonclick intents to a pendingIntent in my RathuMakara.java Service class. I tried to use CONSTANTS, but I was not successful

Solution 1:

Set the notification content

NotificationCompat.Builderbuilder=newNotificationCompat.Builder(this, CHANNEL_ID)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle(textTitle)
    .setContentText(textContent)
    .setPriority(NotificationCompat.PRIORITY_DEFAULT);

and add action buttons

IntentsnoozeIntent=newIntent(this, MyBroadcastReceiver.class);
    snoozeIntent.setAction(ACTION_SNOOZE);
    snoozeIntent.putExtra(EXTRA_NOTIFICATION_ID, 0);
    PendingIntentsnoozePendingIntent=
        PendingIntent.getBroadcast(this, 0, snoozeIntent, 0);

NotificationCompat.Builderbuilder=newNotificationCompat.Builder(this, CHANNEL_ID)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!")
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .setContentIntent(pendingIntent)
        .addAction(R.drawable.ic_snooze, getString(R.string.snooze),
                snoozePendingIntent);

Post a Comment for "Can Not Connect Button Click Action Intent In Main Activity To A Pending Intent In Service Class To Get Action In Notification Using .getaction()"