How to set the Application ARN for Amazon push SNS using Android SDK
amazon-sns, android
Solution
You have 2 instances `CreatePlatformEndpointRequest` and you're setting the token and applicationArn on one but using the other for your SNSClient request so it's missing the required parameters.
String platformApplicationArn = "arn:aws:sns:us-east-1:897955111111:app/GCM/com.myapp";
AWSCredentials awsCredentials = new BasicAWSCredentials("XXXXXXXX", "XXXXXXXXXXXXXXXXXXXXX");
AmazonSNSClient pushClient = new AmazonSNSClient(awsCredentials);
//probably no need for this
String customPushData = "my custom data";
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
platformEndpointRequest.setCustomUserData(customPushData);
platformEndpointRequest.setToken(pushNotificationRegId);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
Also, unless your SNS app Region is US_EAST_1, I've found you have to manually set the region or you'll receive a mismatching region error response, so before calling `createPlatformEndpoint()` set your region like follows:
//Replace with whatever region your app is
pushClient.setRegion(Region.getRegion(Regions.US_WEST_2));
Problem
I am trying to register my Android device to receive push notifications, however the amazon server is returning an error saying it cannot find my PlatformApplicationArn. I am setting it using their sdk but it seems not to be finding it. This is the error: AWS Error Message: Invalid parameter: PlatformApplicationArn Reason: no value for required parameter This is the code that sends it: ``` String platformApplicationArn = "arn:aws:sns:us-east-1:897955111111:app/GCM/com.myapp"; AWSCredentials awsCredentials = new BasicAWSCredentials("XXXXXXXX", "XXXXXXXXXXXXXXXXXXXXX"); pushClient = new AmazonSNSClient(awsCredentials); CreatePlatformEndpointRequest createPlatformEndpointRequest = new CreatePlatformEndpointRequest(); String customPushData = "my custom data"; CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest(); platformEndpointRequest.setCustomUserData(customPushData); platformEndpointRequest.setToken(pushNotificationRegId); platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn); CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(createPlatformEndpointRequest); ```