0

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?

desidigitalnomad
  • 1,443
  • 21
  • 33

1 Answers1

1

The API you are looking for is the Pinpoint.sendMessages API.

REST Documentation

JavaDoc for sendMessages

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()
                                )
                )
)
Cheruvian
  • 5,628
  • 1
  • 24
  • 34
  • Thanks man! I was jumping with excitement when I saw this answer but unfortunately, the API isn't available in the Android SDK :(. Have edited my question to make it more clearer. Is there something similar available in Android SDK? – desidigitalnomad Nov 14 '17 at 12:01
  • You're right unfortunately it doesn't look like they included it with the stripped down version of the Pinpoint SDK. Can you just import the full SDK like you did with the SNS SDK? – Cheruvian Nov 20 '17 at 19:53