Android 从通知中获取待决内容的RegisterReceiver

Android 从通知中获取待决内容的RegisterReceiver,android,android-intent,notifications,intentfilter,Android,Android Intent,Notifications,Intentfilter,我在某个点显示一个通知,点击该通知时将打开一个活动(活动a)。我已尝试向IntentFilter注册接收器,以侦听用户点击通知。我想要的是,避免系统在活动A已经存在时再次启动活动。遗憾的是,接受者从未被呼叫过 这是启动通知的代码: //Create the BackStack for the back navigation when opening from intent TaskStackBuilder builder = TaskStackBuilder.create(this); //C

我在某个点显示一个通知,点击该通知时将打开一个活动(活动a)。我已尝试向IntentFilter注册接收器,以侦听用户点击通知。我想要的是,避免系统在活动A已经存在时再次启动活动。遗憾的是,接受者从未被呼叫过

这是启动通知的代码:

//Create the BackStack for the back navigation when opening from intent
TaskStackBuilder builder = TaskStackBuilder.create(this);

//Create the intent to open this activity, allowing the implementing class add some parameters
Intent thisClassIntent = new Intent(this, ActivityA.class);
onPrepareIntent(thisClassIntent);
thisClassIntent.setAction(ACTION_OPEN_CHAT);

builder.addParentStack(this);
builder.addNextIntent(thisClassIntent);

PendingIntent pendingIntent = builder.getPendingIntent(0, 
PendingIntent.FLAG_UPDATE_CURRENT);

Notification.Builder builder = new Notification.Builder(context).setContentTitle("some title")
                .setContentText("some text")
                .setSmallIcon(R.drawable.icon)
                .setPriority(Notification.PRIORITY_MAX)
                .setDefaults(Notification.DEFAULT_ALL)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent);

Notification notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(0, notification);
在这项活动中,我试图倾听意图中定义的动作:

public class ActivityA extends AppCompatActivity {

private BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        //This should be called when the user taps in the notification
    }
};

@Override
protected void onStart() {
    super.onStart();
    registerReceiver(mReceiver, new IntentFilter(ACTION_OPEN_CHAT));
}

...
}
如果你有任何线索就好了。
谢谢

TaskStackBuilder
创建的
PendingContent
用于
活动
目标,而不是
广播接收器
目标。如果你想让你的通知发送一个专门的广播,你需要为一个
BroadcastReceiver
创建你自己的
pendingent
,并让你的
活动为它注册一个接收者。

你是否在安卓清单中声明了激活你的广播接收者的意图?