【问题标题】:AWS PinPoint - Sending push notifications FROM Android deviceAWS PinPoint - 从 Android 设备发送推送通知
【发布时间】:2017-11-14 07:57:43
【问题描述】:

我需要在 Android 设备之间为 AWS Mobile Hub 项目发送推送通知。它只是设备到设备消息传递,不涉及任何主题。我已经集成了 FCM 和 PinPoint

pinpointManager.getNotificationClient().registerDeviceToken(newToken)

我正在使用此代码获取 endPointID

String epID = pinpointManager.getTargetingClient().currentEndpoint().getEndpointId();

我可以使用上面的 endPointID 从 PinPoint 控制台成功地将消息推送到设备。但我想从 android 设备本身推送。但是,由于 PinPoint Android SDK 中没有任何发布 API,我已经集成了 SNS。我正在尝试使用从 PinPoint 收到的端点 ID 使用此代码通过 SNS 发布:

PublishRequest publishRequest = new PublishRequest();
publishRequest.setTargetArn(epID);
publishRequest.setMessage("Hello from android");

AmazonSNSClient snsClient = new AmazonSNSClient(App.getCCCProvider());
snsClient.publish(publishRequest);

但收到以下异常

com.amazonaws.services.sns.model.InvalidParameterException:无效参数:TargetArn 原因:ARN 必须至少有 6 个元素,而不是 1 个(服务:AmazonSNS;状态代码:400;错误代码:InvalidParameter;请求 ID: 7ff39768-c6f9-5a6e-8211-c5ec586276fb)

如果有帮助,我的 endpointID 是:1fa93529-a5ac-4d70-995a-be1584c68a37

你们有什么建议或解决方案吗?

【问题讨论】:

    标签: android amazon-web-services amazon-sns aws-mobilehub aws-pinpoint


    【解决方案1】:

    您要查找的 API 是 Pinpoint.sendMessages API。

    REST Documentation

    JavaDoc for sendMessages

    您的请求可能类似于:

    amazonPinpoint.sendMessages(
            new SendMessagesRequest()
                    .withApplicationId("APP_ID")
                    .withMessageRequest(
                            new MessageRequest()
                                    .withMessageConfiguration(
                                            new DirectMessageConfiguration()
                                                    .withGCMMessage(
                                                            new GCMMessage()
                                                                    .withBody("Hello from android")
                                                    )
                                    )
                                    .addEndpointsEntry(
                                            "DESTINATION_ENDPOINT_ID",
                                            // You can provide overrides and the like here
                                            new EndpointSendConfiguration()
                                    )
                    )
    )
    

    【讨论】:

    • 谢谢你!当我看到这个答案时,我兴奋得跳了起来,但不幸的是,Android SDK 中没有该 API :(。已编辑我的问题以使其更清晰。Android SDK 中是否有类似的东西可用?
    • 你说得对,不幸的是,他们似乎没有将它包含在 Pinpoint SDK 的精简版中。您可以像使用 SNS SDK 一样导入完整的 SDK 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    相关资源
    最近更新 更多