Android:错误com.parse.ParseException:必须在此操作中指定至少一个ID字段(installationId,deviceToken)

时间:2014-04-14 10:32:53

标签: android push-notification parse-platform device

我在我们的应用程序中使用解析推送通知但在设备注册时出现了一些问题,错误如下所示。当我们向设备发送推送通知时,还有一个问题,即设备收到多个通知。虽然我们还将解析库升级到Parse 1.4.1。请提前帮助我,谢谢。

第一次安装应用时显示

错误

04-14 14:00:40.004: E/LOG(26045): Socket event: onConnect 
04-14 14:00:41.874: E/ParseCommandCache(26045): Failed to run command.
04-14 14:00:41.874: E/ParseCommandCache(26045): com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.ParseCommand$2.then(ParseCommand.java:348)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$10.run(Task.java:452)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$1.execute(Task.java:68)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.completeImmediately(Task.java:448)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.continueWith(Task.java:322)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.continueWith(Task.java:333)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$8.then(Task.java:385)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$8.then(Task.java:377)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$11.run(Task.java:485)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$1.execute(Task.java:68)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.completeAfterTask(Task.java:481)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.access$300(Task.java:18)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$7.then(Task.java:350)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$7.then(Task.java:347)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.runContinuations(Task.java:514)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.access$700(Task.java:18)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:569)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$TaskCompletionSource.setResult(Task.java:603)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$11$1.then(Task.java:497)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$11$1.then(Task.java:489)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$10.run(Task.java:452)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$1.execute(Task.java:68)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.completeImmediately(Task.java:448)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.access$200(Task.java:18)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$6.then(Task.java:315)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$6.then(Task.java:312)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.runContinuations(Task.java:514)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.access$700(Task.java:18)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:569)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$TaskCompletionSource.setResult(Task.java:603)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$11$1.then(Task.java:497)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$11$1.then(Task.java:489)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$10.run(Task.java:452)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$1.execute(Task.java:68)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.completeImmediately(Task.java:448)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.continueWith(Task.java:322)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.continueWith(Task.java:333)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$11.run(Task.java:489)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$1.execute(Task.java:68)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.completeAfterTask(Task.java:481)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.access$300(Task.java:18)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$7.then(Task.java:350)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$7.then(Task.java:347)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.runContinuations(Task.java:514)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task.access$700(Task.java:18)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:569)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$TaskCompletionSource.setResult(Task.java:603)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at com.parse.Task$3.run(Task.java:228)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-14 14:00:41.874: E/ParseCommandCache(26045):     at java.lang.Thread.run(Thread.java:841)

更新了代码

    Parse.initialize(this, Constant.PARSE_APP_ID, Constant.PARSE_CLIENT_KEY);
    ParseACL defaultACL = new ParseACL();
    defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
    PushService.setDefaultPushCallback(this, MainActivity.class);
    ParseInstallation.getCurrentInstallation().getInstallationId();
    ParseInstallation.getCurrentInstallation().saveInBackground();

这是我在parse.com上注册时使用的代码

   PushService.subscribe(this, "name",Detail.class);

这是我用于注册chanels的代码

4 个答案:

答案 0 :(得分:8)

这里也有同样的问题 这看起来像是一个竞争条件,所以我尝试将setDefaultPushCallback放入一个新的回调中:

ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback()
{
    @Override
    public void done(ParseException e)
    {
        PushService.setDefaultPushCallback(ParseApplication.this, ParseStarterProjectActivity.class);
    }
});

我还没有崩溃(尽管它已经很长时间了)。 我希望这会有所帮助。

答案 1 :(得分:4)

我们遇到了类似的问题:

我们不得不移动:PushService.setDefaultPushCallback(this, MainActivity.class);

MainActivity#onCreate中,我们尝试在我们的应用程序类中调用它,但是已兑现。

Parse在这件事上真的无益,希望其中之一并提供一些见解。

答案 2 :(得分:3)

我做了类似的异常。当用户使用Facebook登录应用程序时,我将ACL保存到安装中。 (执行此操作时,服务器上尚不存在安装。)

要摆脱异常,我使用saveEventually()代替saveInBackground() 。这使得Exception消失了,安装将使用它的ACL正确保存到服务器。

答案 3 :(得分:0)

您需要在项目中创建一个从Application

扩展的类
public class YourApplicationName extends Application  {


  @Override
   public void onCreate() {
    super.onCreate();
    Parse.initialize(this, "", "");
  }
}

使用您的解析信息填充""

同时将其添加到清单