简体   繁体   English

在Firebase通知中添加操作按钮?

[英]Add actions buttons in Firebase Notification?

How can I add two actions buttons in Firebase Notification? 如何在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();
}

} }

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. 我认为您通过注册广播接收器来处理来自CMS的传入通知并清除“通知”区域,正朝着正确的方向前进。

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. 然后,您可以使用NotificationManager显示通知。 So you are not displaying the CMS notification but a locally created one with Actions instead. 因此,您不是在显示CMS通知,而是在本地创建带有Actions的通知。

Examples are provided here . 这里提供示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM