当应用程序在Android上处于前台时,不会显示Amazon Pinpoint推送通知

当应用程序在Android上处于前台时,不会显示Amazon Pinpoint推送通知,android,push-notification,aws-pinpoint,Android,Push Notification,Aws Pinpoint,我正在使用Firebase通过Pinpoint处理推送通知 当应用程序不在前台时,我可以接收推送通知。但是,当应用程序打开时,我没有收到它 我查看了PushListenerService代码,它有如下内容: @Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); Log.d(TAG, "Message: " + r

我正在使用Firebase通过Pinpoint处理推送通知

当应用程序不在前台时,我可以接收推送通知。但是,当应用程序打开时,我没有收到它

我查看了PushListenerService代码,它有如下内容:

 @Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Log.d(TAG, "Message: " + remoteMessage.getData());

    final NotificationClient notificationClient= NofiticaiontProvider.getNotificationClient();

    final NotificationDetails notificationDetails = NotificationDetails.builder()
            .from(remoteMessage.getFrom())
            .mapData(remoteMessage.getData())
            .intentAction(NotificationClient.FCM_INTENT_ACTION)
            .build();

    NotificationClient.CampaignPushResult pushResult = notificationClient.handleCampaignPush(notificationDetails);

    if (!NotificationClient.CampaignPushResult.NOT_HANDLED.equals(pushResult)) {
        /**
         The push message was due to a Pinpoint campaign.
         If the app was in the background, a local notification was added
         in the notification center. If the app was in the foreground, an
         event was recorded indicating the app was in the foreground,
         for the demo, we will broadcast the notification to let the main
         activity display it in a dialog.
         */
        if (NotificationClient.CampaignPushResult.APP_IN_FOREGROUND.equals(pushResult)) {
            /* Create a message that will display the raw data of the campaign push in a dialog. */

            final HashMap<String, String> dataMap = new HashMap<>(remoteMessage.getData());
            broadcast(remoteMessage.getFrom(), dataMap);
        }
        return;
    }
@覆盖
收到消息时公共无效(RemoteMessage RemoteMessage){
super.onMessageReceived(remoteMessage);
Log.d(标记,“Message:+remoteMessage.getData());
final NotificationClient NotificationClient=nofiticationtprovider.getNotificationClient();
final NotificationDetails NotificationDetails=NotificationDetails.builder()
.from(remoteMessage.getFrom())
.mapData(remoteMessage.getData())
.intentAction(NotificationClient.FCM\u INTENT\u ACTION)
.build();
NotificationClient.ActivityPushResult pushResult=NotificationClient.HandleCampaingPush(notificationDetails);
如果(!NotificationClient.ActivityPushResult.NOT_HANDLED.equals(pushResult)){
/**
推送消息是由于一次精确定位活动。
如果应用程序位于后台,则会添加本地通知
在通知中心。如果应用程序位于前台,则
事件被记录,表明应用程序位于前台,
对于演示,我们将广播通知,让主
活动在对话框中显示它。
*/
if(前台中的NotificationClient.activitypushresult.APP_等于(pushResult)){
/*创建一条消息,在对话框中显示活动推送的原始数据*/
final HashMap dataMap=newhashmap(remoteMessage.getData());
广播(remoteMessage.getFrom(),dataMap);
}
返回;
}
我曾考虑过使用if语句(App in Foreground one),这样会得到正确的结果。但事实证明,sdk内部有逻辑,如果它在前台,就不会显示通知

下面是SDK中的一个小片段

public final NotificationClient.CampaignPushResult handleCampaignPush(NotificationDetails notificationDetails) {
    final String from = notificationDetails.getFrom();
    final Bundle data = notificationDetails.getBundle();
    final Class<?> targetClass = notificationDetails.getTargetClass();
    String intentAction = notificationDetails.getIntentAction();
    notificationChannelId = notificationDetails.getNotificationChannelId();

    // Check if push data contains a Campaign Id
    if (data == null || !data.containsKey(CAMPAIGN_ID_PUSH_KEY)) {
        return NotificationClient.CampaignPushResult.NOT_HANDLED;
    }

    final boolean isAppInForeground = appUtil.isAppInForeground();

    final String imageUrl = data.getString(CAMPAIGN_IMAGE_PUSH_KEY);
    final String imageIconUrl = data.getString(CAMPAIGN_IMAGE_ICON_PUSH_KEY);
    final String imageSmallIconUrl = data.getString(CAMPAIGN_IMAGE_SMALL_ICON_PUSH_KEY);
    final Map<String, String> campaignAttributes = new HashMap<String, String>();

    campaignAttributes.put(CAMPAIGN_ID_ATTRIBUTE_KEY, data.getString(CAMPAIGN_ID_PUSH_KEY));
    campaignAttributes.put(CAMPAIGN_TREATMENT_ID_ATTRIBUTE_KEY, data.getString(CAMPAIGN_TREATMENT_ID_PUSH_KEY));
    campaignAttributes.put(CAMPAIGN_ACTIVITY_ID_ATTRIBUTE_KEY, data.getString(CAMPAIGN_ACTIVITY_ID_PUSH_KEY));

    this.pinpointContext.getAnalyticsClient().setCampaignAttributes(campaignAttributes);
    log.info("Campaign Attributes are:" + campaignAttributes);

    if (AWS_EVENT_TYPE_OPENED.equals(from)) {
        return this.handleNotificationOpen(campaignAttributes, data);
    }

    // Create the push event.
    String eventType = null;
    if (isAppInForeground) {
        eventType = AWS_EVENT_TYPE_RECEIVED_FOREGROUND;
    } else {
        eventType = AWS_EVENT_TYPE_RECEIVED_BACKGROUND;
    }
public final NotificationClient.activitypushresult handleCampaignPush(NotificationDetails NotificationDetails){
最后一个字符串from=notificationDetails.getFrom();
最终捆绑数据=notificationDetails.getBundle();
最终类targetClass=notificationDetails.getTargetClass();
String intentAction=notificationDetails.getIntentAction();
notificationChannelId=notificationDetails.getNotificationChannelId();
//检查推送数据是否包含活动Id
if(data==null | |!data.containsKey(活动标识键)){
返回NotificationClient.ActivityPushResult.NOT_处理;
}
最终布尔值isappingforeground=appUtil.isappingforeground();
最终字符串imageUrl=data.getString(活动\u图像\u按键);
最终字符串imageIconUrl=data.getString(活动\图像\图标\按键);
最终字符串imageSmallIconUrl=data.getString(活动\u图像\u小图标\u按键);
最终映射活动属性=新HashMap();
campaignAttributes.put(CAMPAIGN_ID_ATTRIBUTE_KEY,data.getString(CAMPAIGN_ID_PUSH_KEY));
campaignAttributes.put(CAMPAIGN_TREATMENT_ID_ATTRIBUTE_KEY,data.getString(CAMPAIGN_TREATMENT_ID_PUSH_KEY));
campaignAttributes.put(CAMPAIGN_ACTIVITY_ID_ATTRIBUTE_KEY,data.getString(CAMPAIGN_ACTIVITY_ID_PUSH_KEY));
this.pinpointContext.getAnalyticsClient().SetActivationAttributes(ActivationAttributes);
log.info(“活动属性为:“+campaignAttributes”);
如果(AWS事件类型打开等于(从)){
返回此.handleNotificationOpen(活动属性、数据);
}
//创建推送事件。
字符串eventType=null;
如果(前景){
eventType=AWS\u事件\u类型\u接收\u前台;
}否则{
eventType=AWS\u事件\u类型\u接收\u背景;
}
事件类型可能是应用程序处于前台时通知不显示的原因。除了提取信息和创建我自己的通知之外,是否有其他方法可以绕过此问题

我找不到任何合适的文档。有人能帮我吗


一切都让我想到了这一点

没有什么神秘的东西-这是出于设计。当应用程序位于前台时,Amazon SDK不会创建相应的通知,而你在PushListenerService中的代码会发送本地广播。

你知道为什么应用程序位于前台时它不会显示通知吗?不,这仍然是一个谜。因此我所做的是,我刚从PushListenerService收到有效负载并抛出我自己的通知。因此,我使用pinpoint只是为了获取信息。如果您有新问题,请单击按钮提问。如果有助于提供上下文,请包含指向此问题的链接。