将令牌注册发送到服务器不工作

时间:2016-10-10 04:35:06

标签: android amazon-web-services amazon-sns

我正在尝试向服务器发送推送通知,然后使用FCM和Amazon SNS将该数据传输到客户端应用程序。

我已经实施了以下内容。

String customPushData = "my custom data";
CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();

platformEndpointRequest.setCustomUserData(customPushData);
platformEndpointRequest.setToken(token);
platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
pushClient.setRegion(Region.getRegion(Regions.AP_NORTHEAST_1));

CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
String endpointArn = result.getEndpointArn();

当我试图调试这个时。然后,

光标没有从

移动
CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);

当我在 console.aws.amazon.com/sns 中签入我的应用程序时,没有注册令牌。

我哪里错了,如何处理将数据发送到sns并返回另一台设备?

任何肝脏都会非常感激。

1 个答案:

答案 0 :(得分:0)

最后,我使用以下方式使其工作。

我已加入AsyncTask并执行以下更改。

new AsyncTask<Void, Void, Void>(){

            @Override
            protected Void doInBackground(Void... params) {

                AWSCredentials awsCredentials = new BasicAWSCredentials("access Key", "secret Key");
                AmazonSNSClient pushClient = new AmazonSNSClient(awsCredentials);

                CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
                platformEndpointRequest.setToken(regToken);
                platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
                pushClient.setRegion(Region.getRegion(Regions.Region_Name));

                CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
                Log.e("Registration result",result.toString());

         return null;
}

我收到了endpointARN作为回应。