我已经能够让我的移动安卓应用程序接收到从定位运动控制台(https://console.aws.amazon.com/pinpoint/home)生成的消息到特定的设备,方法是将该部分定位到只有该设备具有的自定义属性上。
精确运动配置
现在,我想使用SDK在我的Java应用程序中实现这个特性,并针对设备的精确端点。
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);"body“与我在Pinpoint活动控制台中输入的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个状态代码和DeliveryStatus的成功,但应用程序从来没有收到)。我尝试在AWS定位控制台中使用"Direct“消息,但它们似乎不支持相同的格式(强制操作和标题/消息,而不是带有自定义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的直接信息是通过同样的活动方式发送的,还是我必须注册不同的服务来处理这些信息?
发布于 2018-01-05 19:56:02
根据我能够运行的AWS命令找到解决方案。应该使用"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);https://stackoverflow.com/questions/48105300
复制相似问题