gpt4 book ai didi

android - 以编程方式使用 Amazon pinpoint 发送推送通知

转载 作者:搜寻专家 更新时间:2023-11-01 08:19:20 24 4
gpt4 key购买 nike

我正在尝试通过 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 是有效 token ,应用程序 ID 是有效的。

我不确定我是否在 API 中设置了正确的参数?我阅读了文档并添加了我认为需要的所有内容。

android端收到消息但是data为空

这是 Android 端代码。我正在扩展 FirebaseMessagingService 并根据 AWS 设置文档在 list 中注册了服务。

@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 控制台发送消息,并使用我在自己的服务器上使用的相同 token 。

如果您有任何问题,请告诉我。

最佳答案

用一些参数再次播放。这些参数集起作用。我的假设是 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))
})

关于android - 以编程方式使用 Amazon pinpoint 发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53437164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com