注册端点 - 成员不能为空(服务:AmazonSNS;

时间:2017-06-04 23:56:20

标签: android amazon-web-services firebase firebase-cloud-messaging amazon-sns

在Android 4.2.2,API 17(模拟)上进行测试。这适用于API 21+(硬件和模拟设备)。

  

引起:com.amazonaws.AmazonServiceException:1验证错误   检测到:'token'处的值null无法满足约束:Member   不得为null(服务:AmazonSNS;状态代码:400;错误代码:   ValidationError;请求ID:

使用firebase令牌使用下面的方法注册设备端点(到AWS SNS)并获得上述错误。它在线失败

    CreatePlatformEndpointResult cpeRes = client.createPlatformEndpoint(cpeReq);

方法:

private String createEndpoint() {
    String endpointArn = null;
    try {
        System.out.println("Creating platform endpoint with token " + token);
        CreatePlatformEndpointRequest cpeReq =
                new CreatePlatformEndpointRequest()
                        .withPlatformApplicationArn(applicationArn)
                        .withToken(token);
        CreatePlatformEndpointResult cpeRes = client.createPlatformEndpoint(cpeReq);
        endpointArn = cpeRes.getEndpointArn();
    } catch (Exception ipe) {
        String message = ipe.toString();
        System.out.println("Exception message: " + message);
        Pattern p = Pattern
                .compile(".*Endpoint (arn:aws:sns[^ ]+) already exists " +
                        "with the same token.*");
        Matcher m = p.matcher(message);
        if (m.matches()) {
            // The platform endpoint already exists for this token, but with
            endpointArn = m.group(1);
        } else {
            // Rethrow the exception, the input is actually bad.
            throw ipe;
        }
    }
    storeEndpointArn(endpointArn);
    return endpointArn;
}

1 个答案:

答案 0 :(得分:0)

因此,在使用代码几个小时之后,问题不在于代码,而在于模拟器。

Google Play Services

  

要使用Google Play服务API开发应用,您需要进行设置   使用Google Play服务SDK启动您的项目。

     

如果您还没有安装Google Play服务SDK,那就去吧   现在按照添加SDK包的指南进行操作。

     

要在使用Google Play服务SDK时测试您的应用,您必须使用   之一:

     

运行Android 2.3或更高版本的兼容Android设备   包括Google Play商店。运行AVD的Android模拟器   基于Android 4.2.2或更高版本的Google API平台。

所以在API 17 ...

  

API 17( Android 4.2-4.2.2 ) - Jelly Bean,于2012年11月发布。构建   版本代码Android.OS.BuildVersionCodes.JellyBeanMr1

因此,要在API 17及更高版本上进行模拟,请打开SDK安装程序,并显示包详细信息。在要模拟的API版本中,安装与Google API相关的所有软件包。 This为您提供了一个主意。

enter image description here