如何在Android中取消推送通知默认对话框

时间:2018-04-13 15:16:46

标签: android push-notification dialog

当应用处于Foreground状态时,我会看到dialog框,其中包含通知标题和正文。我不想显示此dialog框。相反,我想使用我自己的dialog框。我对Push Notification功能很新,很抱歉,如果这是一个愚蠢的问题。我已经附加了我现在正在获取的dialog框的示例图像。 enter image description here

这是我的代码

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Intent intent = new Intent(Cons.INTENT_FILTER);
    Bundle bundle = new Bundle();
    // some custom data in bundle which I need.
    intent.putExtras(bundle);
    sendBroadcast(intent);
}

我正在使用BroadcastReceiver来处理通知

private BroadcastReceiver myReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
};

我也在注册和取消注册BroadcastReceiver

registerReceiver(myReceiver, new IntentFilter(Cons.INTENT_FILTER));

unregisterReceiver(myReceiver);

1 个答案:

答案 0 :(得分:0)

尝试注册/取消注册接收器

IntentFilter filter = new IntentFilter();
filter.addAction(Cons.INTENT_FILTER);
registerReceiver(myReceiver, filter)
// then unregisterReceiver(myReceiver);