首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Amazon pinpiont编程发送推送通知

使用Amazon pinpiont编程发送推送通知
EN

Stack Overflow用户
提问于 2018-11-22 19:36:37
回答 1查看 1.5K关注 0票数 2

我正试图通过亚马逊的定位,使用GCM/FCM向android设备发送推送通知。当我在模拟器中调试Android应用程序时,我能够发送消息并看到它,但是消息数据是空的。不确定如何调试所缺少的内容。

我在用boto发送信息。这是示例消息。

代码语言:javascript
复制
response = client.get_gcm_channel(ApplicationId='*****')

    responseSendMsg = client.send_messages(
        ApplicationId='*****',
        MessageRequest={'Addresses': {
        '<token>': {
            'BodyOverride': 'string',
            'ChannelType': 'GCM',
            'Context': {
                'string': 'string'
            },
            'RawContent': 'Raw value of message',
            'Substitutions': {
                'string': [
                    'string',
                ]
            },
            'TitleOverride': 'Title from API'
        }
    },
    'Context': {
        'tKey': 'tValue'
    },
    'MessageConfiguration': {
        'GCMMessage': {
            'Action': 'OPEN_APP',
            'Body': 'Message from message configuration',
            'Data': {
                'testDataKey': 'testDataValue'
            },
            'IconReference': 'ic_launchstringer.png',
            'ImageIconUrl': 'string',
            'ImageUrl': 'string',
            'Priority': 'High',
            'RawContent': 'test raw content',
            'RestrictedPackageName': 'string',
            'SilentPush': True,
            'SmallImageIconUrl': 'string',
            'Sound': 'string',
            'Substitutions': {
                'string': [
                    'string',
                ]
            },
            'TimeToLive': 36000,
            'Title': 'Title from message configuration',
            'Url': 'string'
        }
    },
    'TraceId': 'test Trace Id' + str(round(time.time()*1000))
})

注意,令牌是有效的令牌,应用程序id是有效的。

我不确定的是我是否在API中设置了正确的参数?我阅读了文档,并添加了我认为需要的所有内容。

android端的消息已经收到,但是data是空的。

这是Android端代码。我正在扩展FirebaseMessagingService,并按照安装时的AWS文档在清单中注册了服务。

代码语言:javascript
复制
@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        Log.d(TAG, "Message: " + remoteMessage.getData());

        final NotificationClient notificationClient = HomeActivity.getPinpointManager(getApplicationContext()).getNotificationClient();

        final HashMap<String, String> dataMap1 = new HashMap<>(remoteMessage.getData());

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

如果有人使用了这个api,并可以向我介绍一个直接调用api或通过某个客户端包的示例,这将是非常有帮助的。

注意:我能够使用AWS控制台发送消息,并使用与我自己的服务器使用的相同的令牌。

如果你有任何问题,请告诉我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-22 20:11:01

又玩了一些参数。这些参数集起作用。我的假设是,当FCM看到针对不同用例的重写时,它无法将数据发送到FCM。AWS团队应该明确地添加文档,哪些是所需的,哪些是不使用他们的apis。无论如何,对于调试人员来说,这可能是有用的。

代码语言:javascript
复制
    response = client.get_gcm_channel(ApplicationId='*****')

    responseSendMsg = client.send_messages(
        ApplicationId='*****',
        MessageRequest={'Addresses': {
        '<token>': {
            'ChannelType': 'GCM',
            'TitleOverride': 'Title from API'
        }
    },
    'MessageConfiguration': {
        'GCMMessage': {
            'Action': 'OPEN_APP',
            'Body': 'Message from message configuration',
            'Priority': 'High',
            'SilentPush': False,
            'TimeToLive': 36000,
            'Title': 'Title from message configuration'
        }
    },
    'TraceId': 'test Trace Id' + str(round(time.time()*1000))
})
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53437164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档