【问题标题】:Add actions buttons in Firebase Notification?在 Firebase 通知中添加操作按钮?
【发布时间】:2017-06-14 18:50:31
【问题描述】:

如何在 Firebase 通知中添加两个操作按钮? 我的通知工作正常。我想添加两个操作按钮-接受和拒绝 我尝试添加按钮,但没有任何代码起作用。 这是我的代码。帮帮我!

  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();
}

}

【问题讨论】:

    标签: android firebase firebase-cloud-messaging android-notifications


    【解决方案1】:

    我认为通过注册广播接收器来处理来自 CMS 的传入通知并清除通知区域,您正在走上正确的道路。

    现在您需要在应用程序中创建一个通知,向通知添加操作并定义待处理的意图来处理这些操作。然后您可以使用 NotificationManager 显示通知。因此,您不会显示 CMS 通知,而是显示本地创建的带有操作的通知。

    提供示例here。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-22
      • 2016-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多