1

How can I add two actions buttons in Firebase Notification? My Notification is working totally fine.I want to add two Actions buttons-Accept and Reject I tried to add buttons but none of the code worked. Here is my code.Help me out!

  mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
                FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
                displayFirebaseRegId();
            } else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
                String message = intent.getStringExtra("message");
                Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show();
                txtMessage.setText(message);
            }
        }
    };

    displayFirebaseRegId();
}

private void displayFirebaseRegId() {
    SharedPreferences pref = getApplicationContext().getSharedPreferences(Config.SHARED_PREF, 0);
    String regId = pref.getString("regId", null);

    Log.e(TAG, "Firebase reg id: " + regId);

    if (!TextUtils.isEmpty(regId))
        txtRegId.setText("Firebase Reg Id: " + regId);
    else
        txtRegId.setText("Firebase Reg Id is not received yet!");
}

@Override
protected void onResume() {
    super.onResume();

    // register GCM registration complete receiver
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(Config.REGISTRATION_COMPLETE));

    // register new push message receiver
    // by doing this, the activity will be notified each time a new message arrives
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(Config.PUSH_NOTIFICATION));

    // clear the notification area when the app is opened
    NotificationUtils.clearNotifications(getApplicationContext());
}

@Override
protected void onPause() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
    super.onPause();
}

}

AL.
  • 36,815
  • 10
  • 142
  • 281

1 Answers1

0

I think you are going down the right path by registering a Broadcast Receiver to handle the incoming notification from the CMS and clearing out the Notification area.

Now you need to create a Notification from within the app, add actions to the Notification and define Pending Intents to handle the actions. Then you can display the Notification using the NotificationManager. So you are not displaying the CMS notification but a locally created one with Actions instead.

Examples are provided here.

checkmate711
  • 3,301
  • 2
  • 35
  • 45