【发布时间】:2018-11-22 19:36:37
【问题描述】:
我正在尝试通过 Amazon pinpoint 使用 GCM/FCM 向 android 设备发送推送通知。当我在模拟器中调试 Android 应用程序但消息数据为空时,我能够发送消息并且可以看到它。不知道如何调试我缺少的东西。
我正在使用 boto 发送消息。这是示例消息。
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))
})
请注意,token 是一个有效的令牌,并且应用程序 id 是有效的。
我不确定我是否在 API 中设置了正确的参数?我阅读了文档并添加了我认为需要的所有内容。
android端的消息收到但是data是空的。
这是 Android 端代码。我正在扩展 FirebaseMessagingService 并已根据 AWS 设置文档在清单中注册服务。
@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 控制台发送消息,并使用与我自己的服务器相同的令牌。
如果您有任何问题,请告诉我。
【问题讨论】:
-
您是否能够从 Pinpoint 控制台发送包含数据的消息并在您的 Android 设备中查看数据?
标签: android push-notification firebase-cloud-messaging boto3 aws-pinpoint