Be informed we are using broadcastreceiver for action intent to dismiss the notification dialog. It works when we use it for the first time, after that it just goes unresponsive. The first time notification pops up, we click dismiss, the action intent works just fine, but onwards from second notification, it stops working.
The code is given below:
Partial code of Android Manifest
<application
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:taskAffinity=""
android:excludeFromRecents="true"
android:noHistory="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/SplashTheme"
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
tools:ignore="AllowBackup,UnusedAttribute">
<receiver android:name=".ButtonReceiver"/>
Button Receiver.Class (broadcast receiver)
public class ButtonReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int notificationId = intent.getIntExtra("notificationId", 0);
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(notificationId);
}
}
Firebase.java
int requestID = (int) System.currentTimeMillis();
int notification_id=m;
Intent buttonIntent = new Intent(this, ButtonReceiver.class);
buttonIntent.putExtra("notificationId",notification_id);
PendingIntent btPendingIntent = PendingIntent.getBroadcast(this, 0, buttonIntent,0);
NotificationCompat.Action action1 = new NotificationCompat.Action.Builder(R.mipmap.ic_launcher, "Dismiss", btPendingIntent).build();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, MainActivity.asw_fcm_channel)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(message)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setTimeoutAfter(60000)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setAutoCancel(false)
.addAction(action1)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(pendingIntent2, true)
.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
Any help would be appreciated.