AWS SNS Android App中的参数无效

时间:2016-10-01 20:12:15

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

我已在我的Android应用中集成了AWS SNS API。当我在设备上打开应用程序时,我收到此错误日志:

E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.intap.appme, PID: 20780
                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.intap.appme/com.intap.appme.MainActivity}: com.amazonaws.services.sns.model.InvalidParameterException: Invalid parameter: Endpoint (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: e8589d7c-dec8-55e1-807f-cd16c8794be8)
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
                                                                 at android.app.ActivityThread.access$1100(ActivityThread.java:221)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:158)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                              Caused by: com.amazonaws.services.sns.model.InvalidParameterException: Invalid parameter: Endpoint (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: e8589d7c-dec8-55e1-807f-cd16c8794be8)
                                                                 at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:712)
                                                                 at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:388)
                                                                 at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199)
                                                                 at com.amazonaws.services.sns.AmazonSNSClient.invoke(AmazonSNSClient.java:2262)
                                                                 at com.amazonaws.services.sns.AmazonSNSClient.subscribe(AmazonSNSClient.java:1256)
                                                                 at com.amazonaws.mobile.push.PushManager.subscribeToTopic(PushManager.java:251)
                                                                 at com.intap.appme.MainActivity.onCreate(MainActivity.java:50)
                                                                 at android.app.Activity.performCreate(Activity.java:6876)
                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                                                                 at android.app.ActivityThread.access$1100(ActivityThread.java:221) 
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                 at android.os.Looper.loop(Looper.java:158) 
                                                                 at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

日志中的代码行是那些行: PushManager.java:251(整个方法)

public void subscribeToTopic(final SnsTopic topic) {
    final SubscribeRequest request = new SubscribeRequest();
    request.setEndpoint(endpointArn);
    request.setTopicArn(topic.getTopicArn());
    request.setProtocol(SNS_PROTOCOL_APPLICATION);
    /* Line 251 -> */ final SubscribeResult result = sns.subscribe(request);

    // update topic and save subscription in shared preferences
    final String subscriptionArn = result.getSubscriptionArn();
    topic.setSubscriptionArn(subscriptionArn);
    sharedPreferences.edit().putString(topic.getTopicArn(), subscriptionArn).apply();
}

MainActivity.java:50

pushManager.subscribeToTopic(pushManager.getDefaultTopic());

我没有真正意识到我的应用中的无效参数是什么,所以你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

根据日志,无效参数是端点 要获得端点,你可以做...

final CreatePlatformEndpointRequest request = new CreatePlatformEndpointRequest();
    request.setPlatformApplicationArn(platformApplicationArn);
    request.setToken(gcmToken);
    final CreatePlatformEndpointResult result = snsClient.createPlatformEndpoint(request);

可以通过以下方式检索端点:

    result.getEndpointArn();