Reputation: 1443
I need to send push notifications between Android devices for an AWS Mobile Hub project. It is only device-to-device messaging, no topics involved. I have already integrated FCM and PinPoint
pinpointManager.getNotificationClient().registerDeviceToken(newToken)
I'm getting the endPointID using this code
String epID = pinpointManager.getTargetingClient().currentEndpoint().getEndpointId();
I can successfully push messages to the device from PinPoint console using the above endPointID. But I want to push from the android device itself. However, since there isn't any publish API available in PinPoint Android SDK, I have integrated SNS. I'm trying to publish with SNS using the endpointID received from PinPoint using this code:
PublishRequest publishRequest = new PublishRequest();
publishRequest.setTargetArn(epID);
publishRequest.setMessage("Hello from android");
AmazonSNSClient snsClient = new AmazonSNSClient(App.getCCCProvider());
snsClient.publish(publishRequest);
but receiving the following exception
com.amazonaws.services.sns.model.InvalidParameterException: Invalid parameter: TargetArn Reason: An ARN must have at least 6 elements, not 1 (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: 7ff39768-c6f9-5a6e-8211-c5ec586276fb)
If it helps, my endpointID is : 1fa93529-a5ac-4d70-995a-be1584c68a37
Any pointers or solutions from you guys?
Upvotes: 0
Views: 1156
Reputation: 5867
The API you are looking for is the Pinpoint.sendMessages
API.
Your request would probably look something like:
amazonPinpoint.sendMessages(
new SendMessagesRequest()
.withApplicationId("APP_ID")
.withMessageRequest(
new MessageRequest()
.withMessageConfiguration(
new DirectMessageConfiguration()
.withGCMMessage(
new GCMMessage()
.withBody("Hello from android")
)
)
.addEndpointsEntry(
"DESTINATION_ENDPOINT_ID",
// You can provide overrides and the like here
new EndpointSendConfiguration()
)
)
)
Upvotes: 1