我遵循AWS Mobile Hub推送集成指南,并在我的应用中集成了AWS SNS推送服务。当我打开应用程序时,我收到此错误日志:
if name == None:
result = Product.objects.all()
else:
result = Product.objects.filter(name = name)
应用程序中提到的代码行是那些行:
PushManager.java:264(整个方法)
android:layout_columnWeight="1"
android:layout_rowWeight="1"
MainActivity.java:50
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.intap.appme, PID: 23576
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.intap.name/com.intap.name.MainActivity}: com.amazonaws.AmazonServiceException: 1 validation error detected: Value null at 'token' failed to satisfy constraint: Member must not be null (Service: AmazonSNS; Status Code: 400; Error Code: ValidationError; Request ID: 21d6a3b2-0459-513a-bf7a-f3c1d99d41ac)
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.AmazonServiceException: 1 validation error detected: Value null at 'token' failed to satisfy constraint: Member must not be null (Service: AmazonSNS; Status Code: 400; Error Code: ValidationError; Request ID: 21d6a3b2-0459-513a-bf7a-f3c1d99d41ac)
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.createPlatformEndpoint(AmazonSNSClient.java:447)
at com.amazonaws.mobile.push.PushManager.subscribeToTopic(PushManager.java:264)
at com.intap.name.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)
当我尝试通过在线Firebase控制台发送推送消息时,设备会收到推送消息,当我点击消息打开应用时,它会一直崩溃。
当我尝试通过在线SNS控制台发送推送消息时,我没有得到任何推送通知,这意味着错误是在向SNS注册时。
我该如何解决?我根本不知道......
答案 0 :(得分:2)
该令牌将从Google的SDK中返回null。原因在于这一行:
endpointRequest.setToken(InstanceID.getInstance(context)
.getToken(sharedPreferences.getString("deviceToken", ""),
GoogleCloudMessaging.INSTANCE_ID_SCOPE));
getToken()的第一个参数应该是GCM发件人ID,而不是从sharedPreferences中提取的设备令牌。更改代码以传递发件人ID,如下所示,应解决问题:
endpointRequest.setToken(InstanceID.getInstance(context)
.getToken(gcmSenderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE));
此外,您粘贴的代码似乎是在相当遥远的过去生成的Mobile Hub项目中修改的。从那时起,PushManager就有了改进。 Mobile Hub生成的最新版本将使用GCMTokenHelper类,该类在您粘贴的代码中不存在。请尝试再次使用移动中心生成示例应用或SDK,并更新您的应用以使用最近生成的代码,如果您仍遇到问题则报告回来。