android - 以编程方式使用 Amazon pinpiont 发送推送通知
问题描述
我正在尝试通过 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 api 在看到不同用例的覆盖时无法将数据发送到 FCM。AWS 团队应明确添加该文档,哪些是需要的,哪些是不使用其 API 的。无论如何可能对调试人员有用。
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))
})
推荐阅读
- instagram - 从企业账户切换到个人账户并重新切换回企业账户,取回已删除的数据
- javascript - 为什么我的 Axios 捕获中未定义错误?
- loops - 如果 product.tags = 'phrase',Shopify For Loop 会模糊图像
- c# - PDFReactor .NET - @page 不存在是当前上下文
- bash - Bash 中的粗体管道文本
- swift - 将棋盘添加到 UIImageView 的透明部分
- html - IE 使用 contenteditable 时会覆盖光标
- java - 在用于测试 Junit4 的函数中模拟私有变量
- python - pytest:`foo is Enum.FOO` 在本地测试 True,在 travis-ci 上测试 False
- angular - 区分由同一父级创建的两个 Angular 组件