1

通过将细分定位到仅该设备有。

查明活动配置

  • 移动推送渠道
  • 标准广告系列
  • 使用自定义属性定义的段,保留 0%
  • 静默通知
  • 自定义 JSON
  • 立即启动

现在我想使用 SDK API 在我的 Java 应用程序中实现此功能,并以设备的 Pinpoint 端点为目标。

GetEndpointRequest getEndpointRequest = new GetEndpointRequest()
   .withApplicationId(appId)
   .withEndpointId(endpointId);
GetEndpointResult endpointResult = getAmazonPinpointClient().getEndpoint(getEndpointRequest);

DirectMessageConfiguration directMessageConfiguration =
  new DirectMessageConfiguration().withGCMMessage(new GCMMessage().withBody(body).withSilentPush(true).withAction(Action.OPEN_APP));
AddressConfiguration addressConfiguration = new AddressConfiguration().withChannelType(ChannelType.GCM);

MessageRequest messageRequest = new MessageRequest().withMessageConfiguration(directMessageConfiguration)
   .addAddressesEntry(endpointResponse.getAddress(), addressConfiguration);

SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
   .withApplicationId(appId)
   .withMessageRequest(messageRequest);

“正文”与我在 Pinpoint Campaign 控制台中放入的 JSON 相同。当我运行它时,我得到一个成功的 DeliveryStatus 但设备从未收到该消息。

{ApplicationId: MY_APP_ID,Result: {clrVUcv-AwA:APA91bHGXkxpDJiw5kOMROA2XTJXuKreMklq9jemHO_KGYTIw6w84Fw9zLv9waMgLgha61IR-kZxgmrnFu-OGp8l6WFgp4Wolh4oOvZwMobGYNgzivv3bGIK83t-e4hiLx1TTaEIeRdQ={DeliveryStatus: SUCCESSFUL,StatusCode: 200,StatusMessage: {"multicast_id":4803589342422496921,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1515105369948916%c551fa42f9fd7ecd"}]},}}}

我也通过 AWS CLI 尝试过:

aws pinpoint send-messages --application-id MY_APP_ID --message-request "{\"Addresses\":{\"clrVUcv-AwA:APA91bHGXkxpDJiw5kOMROA2XTJXuKreMklq9jemHO_KGYTIw6w84Fw9zLv9waMgLgha61IR-kZxgmrnFu-OGp8l6WFgp4Wolh4oOvZwMobGYNgzivv3bGIK83t-e4hiLx1TTaEIeRdQ\":{\"ChannelType\":\"GCM\"}},\"MessageConfiguration\":{\"GCMMessage\":{\"Body\":\"{\\\"message\\\":\\\"stuff\\\"}\",\"SilentPush\":true}}}"

具有类似的结果(获得 200 状态代码和 SUCCESSFUL 的 DeliveryStatus 但应用程序从未收到)。我尝试在 AWS Pinpoint 控制台中使用“直接”消息,但它们似乎不支持相同的格式(强制操作和标题/消息,而不是使用自定义 JSON 的静默推送消息)。

我是否错误地获取了端点?如何将上述活动转化为消息?我看到还有一个 sendUserMessages() API 调用,但这似乎不是正确的(我找不到指定特定用户端点的位置)?

客户通过注册的服务接收活动:

public class PushListenerService extends GcmListenerService {

@Override
public void onMessageReceived(final String from, final Bundle data) {
    AWSMobileClient.initializeMobileClientIfNecessary(this.getApplicationContext());
    final NotificationClient notificationClient = AWSMobileClient.defaultMobileClient()
            .getPinpointManager().getNotificationClient();

    NotificationClient.CampaignPushResult pushResult =
            notificationClient.handleGCMCampaignPush(from, data, this.getClass());


    Log.e(LOG_TAG, " onMessageReceived - got messages"  + data);

GCM 直接消息是通过相同的活动方法发送的,还是我必须注册不同的服务来处理这些消息?

4

1 回答 1

2

根据我能够运行的 AWS CLI 命令找到了解决方案。应该使用“Data”元素而不是“Body”,并且需要启用“SilentPush”。

EndpointResponse endpointResponse = getPinpointEndpointResponse(appId, pinpointEndpointId);

Map<String, String> data = new HashMap<>();
// construct data here, currently only supports Map<String, String>
// why not HashMap<String, Object> so it can support full JSON????

DirectMessageConfiguration directMessageConfiguration =
    new DirectMessageConfiguration().withGCMMessage(new GCMMessage().withData(data).withSilentPush(true));

AddressConfiguration addressConfiguration = new AddressConfiguration().withChannelType(ChannelType.GCM);

MessageRequest messageRequest = new MessageRequest().withMessageConfiguration(directMessageConfiguration)
    .addAddressesEntry(endpointResponse.getAddress(), addressConfiguration);

SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
    .withApplicationId(appId)
    .withMessageRequest(messageRequest);
于 2018-01-05T19:56:02.387 回答