android – “必须在此操作中指定至少一个ID字段(installationId,deviceToken)”解析

前端之家收集整理的这篇文章主要介绍了android – “必须在此操作中指定至少一个ID字段(installationId,deviceToken)”解析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这很简单,当你第一次在手机上使用解析时,它就像一个魅力.
当您重新安装应用程序时,它会拧紧所有内容.

stackoverflowEran所述:

“PushService.subscribe似乎将订阅缓存在本地存储中,以避免在多次启动应用程序时重新订阅.
这是该方法的第一个参数用于:
context – 用于访问本地存储以缓存订阅,因此它当前必须是可行的上下文.
(引自here).

但是,卸载应用程序时,将从您的设备中删除该应用程序的本地存储,因此新安装将导致PushService.subscribe重新注册到Google Cloud Messaging.如果新注册返回新的注册ID,则Parse将具有两个注册ID,可用于向您的应用发送推送通知,并且它们都将链接到您提供给订阅的相同userName.因此,向该userName发送通知会将其发送到两个注册ID,导致它到达两次.

当Parse为您发送通知时,他们应该通过canonical_registration_id从Google获取回复,这会让他们知道您设备上与您的应用相关联的注册ID之一已过时,不应再使用了.因此(假设Parse有一个不错的GCM实现),下次你向设备发送通知时,你应该只收到一次.“

这是我的安装源代码

String  androidId = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
Parse.initialize(this,"KEY1","KEY2");
PushService.setDefaultPushCallback(this,ParseActivity.class);

ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("UniqueId",androidId);

installation.setObjectId(null);

installation.saveInBackground();

我的堆栈跟踪(像每个人一样):

05-20 19:47:35.630: E/ParseCommandCache(6497): com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseCommand.onPostExecute(ParseCommand.java:334)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseRequest$5.then(ParseRequest.java:321)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseRequest$5.then(ParseRequest.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:481)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWithTask(Task.java:353)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWithTask(Task.java:364)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$9.then(Task.java:410)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$9.then(Task.java:402)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:481)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$400(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:346)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:343)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$300(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:311)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:308)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$300(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:311)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$6.then(Task.java:308)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:329)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$400(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:346)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$7.then(Task.java:343)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.runContinuations(Task.java:510)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.access$800(Task.java:22)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:493)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11$1.then(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$10.run(Task.java:448)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeImmediately(Task.java:444)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.continueWith(Task.java:329)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:485)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at java.lang.Thread.run(Thread.java:841)
05-20 19:48:32.615: D/Request(6497): Warning: Sessionless Request needs token but missing either application ID or client token.

由于我没有找到任何真正的解决方案,我在这里问.

谢谢.

解决方法

我绝对相信这是由解析错误引起的.我在Parse.com找到的很多未解决错误报告也说了同样的事情.
我目前正在使用Parse 1.5.1:
我看到的是没有deviceToken就不会发送推送,如果没有uniqueId,我们会在上面得到运行时错误.
如果我在注册后立即发送UniqueId,则会保存没有deviceToken的行.
在Nexus 5,Nexus 4和Sony xperia E上测试的解决方案:
在您的Application类onCreate()中
Parse.initialize(this,PARSE_APP_KEY_VALUE,PARSE_CLIENT_KEY_VALUE);
    PushService.setDefaultPushCallback(getApplicationContext(),MainActivity.class);
    final ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    final String  androidId = Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.ANDROID_ID);
        // Post the uniqueId delayed
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    installation.put("UniqueId",androidId);
                                    installation.saveInBackground(new SaveCallback() {
                                        @Override
                                        public void done(ParseException e) {
                                            // Saved!
                                        }
                                    });
                                }
                            },10000
        );

以这种方式工作,我能够保存正确的行(使用uniqueId和deviceToken),并发送推送通知!干杯!

原文链接:https://www.f2er.com/android/315007.html

猜你在找的Android相关文章