Sending push notification using Amazon pinpiont programatically
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.
android push-notification firebase-cloud-messaging boto3 aws-pinpoint
add a comment |
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.
android push-notification firebase-cloud-messaging boto3 aws-pinpoint
Were you able to send a message with data from Pinpoint console and see the data in your Android device?
– Karthikeyan
Nov 26 at 18:23
add a comment |
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.
android push-notification firebase-cloud-messaging boto3 aws-pinpoint
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.
android push-notification firebase-cloud-messaging boto3 aws-pinpoint
android push-notification firebase-cloud-messaging boto3 aws-pinpoint
edited Nov 22 at 19:47
NinjaCoder
1,16021640
1,16021640
asked Nov 22 at 19:36
Mayank
137114
137114
Were you able to send a message with data from Pinpoint console and see the data in your Android device?
– Karthikeyan
Nov 26 at 18:23
add a comment |
Were you able to send a message with data from Pinpoint console and see the data in your Android device?
– Karthikeyan
Nov 26 at 18:23
Were you able to send a message with data from Pinpoint console and see the data in your Android device?
– Karthikeyan
Nov 26 at 18:23
Were you able to send a message with data from Pinpoint console and see the data in your Android device?
– Karthikeyan
Nov 26 at 18:23
add a comment |
1 Answer
1
active
oldest
votes
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))
})
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437164%2fsending-push-notification-using-amazon-pinpiont-programatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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))
})
add a comment |
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))
})
add a comment |
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))
})
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))
})
answered Nov 22 at 20:11
Mayank
137114
137114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437164%2fsending-push-notification-using-amazon-pinpiont-programatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Were you able to send a message with data from Pinpoint console and see the data in your Android device?
– Karthikeyan
Nov 26 at 18:23