Reputation: 357
I am trying to send push notification to android device using GCM/FCM via Amazon pinpoint. I am able to send the message and can see it when I debug the Android app in the emulator but the message data is empty. Not sure how I can debug what I am missing.
I am using boto to send message. Here is the sample message.
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))
})
Note that token is a valid token and the application id is valid.
What I am not sure is whether I am setting the correct parameters in the API? I read the documentation and added everything I thought is needed.
The message on the android side is received but data
is empty.
Here is the Android side code. I am extending FirebaseMessagingService
and have registered service in the manifest as per AWS documentation on setup.
@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;
}
}
It will be really helpful if someone has used this api and can point me to an example whtether directly calling the api or through some client package.
NOTE: I am able to send message using AWS console and using the same token I am using from my own server.
Let me know if you have any questions.
Upvotes: 2
Views: 2081
Reputation: 357
Played again with some parameters. These set of parameters work. My assumption is pinpoint api fails to send data to FCM when it sees overrides for different use cases. AWS teams should add that documentation explicitly what is required, what is not to use their apis. Anyway might be useful for someone for debugging.
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))
})
Upvotes: 4