场合
我已经在 ANDROID 中使用Parse实现了推送通知。一切都很好(我可以接收推送/发送等),唯一的一件事就是当我安装我的应用程序时,它会发生这样的事情:
生成错误
02-12 11:12:28.054 15564-15579/com.hoxell.hoxellbrowser E/ParseCommandCache﹕ Failed to run command.
com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation
at com.parse.ParseCommand.onPostExecute(ParseCommand.java:404)
at com.parse.ParseRequest$5.then(ParseRequest.java:342)
at com.parse.ParseRequest$5.then(ParseRequest.java:339)
at bolts.Task$10.run(Task.java:486)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeAfterTask(Task.java:482)
at bolts.Task.continueWithTask(Task.java:358)
at bolts.Task.continueWithTask(Task.java:369)
at bolts.Task$8.then(Task.java:415)
at bolts.Task$8.then(Task.java:407)
at bolts.Task$10.run(Task.java:486)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeAfterTask(Task.java:482)
at bolts.Task.access$200(Task.java:27)
at bolts.Task$6.then(Task.java:351)
at bolts.Task$6.then(Task.java:348)
at bolts.Task.runContinuations(Task.java:515)
at bolts.Task.access$600(Task.java:27)
at bolts.Task$TaskCompletionSource.trySetResult(Task.java:570)
at bolts.Task$TaskCompletionSource.setResult(Task.java:604)
at bolts.Task$10$1.then(Task.java:498)
at bolts.Task$10$1.then(Task.java:490)
at bolts.Task$9.run(Task.java:453)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeImmediately(Task.java:449)
at bolts.Task.access$100(Task.java:27)
at bolts.Task$5.then(Task.java:316)
at bolts.Task$5.then(Task.java:313)
at bolts.Task.runContinuations(Task.java:515)
at bolts.Task.access$600(Task.java:27)
at bolts.Task$TaskCompletionSource.trySetResult(Task.java:570)
at bolts.Task$TaskCompletionSource.setResult(Task.java:604)
at bolts.Task$10$1.then(Task.java:498)
at bolts.Task$10$1.then(Task.java:490)
at bolts.Task$9.run(Task.java:453)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeImmediately(Task.java:449)
at bolts.Task.access$100(Task.java:27)
at bolts.Task$5.then(Task.java:316)
at bolts.Task$5.then(Task.java:313)
at bolts.Task.runContinuations(Task.java:515)
at bolts.Task.access$600(Task.java:27)
at bolts.Task$TaskCompletionSource.trySetResult(Task.java:570)
at bolts.Task$TaskCompletionSource.setResult(Task.java:604)
at bolts.Task$10$1.then(Task.java:498)
at bolts.Task$10$1.then(Task.java:490)
at bolts.Task$9.run(Task.java:453)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeImmediately(Task.java:449)
at bolts.Task.continueWith(Task.java:323)
at bolts.Task.continueWith(Task.java:334)
at bolts.Task$10.run(Task.java:490)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeAfterTask(Task.java:482)
at bolts.Task.access$200(Task.java:27)
at bolts.Task$6.then(Task.java:351)
at bolts.Task$6.then(Task.java:348)
at bolts.Task.runContinuations(Task.java:515)
at bolts.Task.access$600(Task.java:27)
at bolts.Task$TaskCompletionSource.trySetResult(Task.java:570)
at bolts.Task$TaskCompletionSource.setResult(Task.java:604)
at bolts.Task$10$1.then(Task.java:498)
at bolts.Task$10$1.then(Task.java:490)
at bolts.Task$9.run(Task.java:453)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
at bolts.Task.completeImmediately(Task.java:449)
at bolts.Task.continueWith(Task.java:323)
at bolts.Task.continueWith(Task.java:334)
at bolts.Task$10.run(Task.java:490)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:864)
是的,它会生成它,但应用程序不会崩溃!该应用程序仍然有效:推送通知,但您可以理解这不是100%可靠。
E/ParseCommandCache﹕ Failed to run command.
com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation
他想要什么......?我该怎么办?问题的原因是什么?这是我的代码:
Application.java
@Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "x", "x");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
在我的mainActivity中,我只是将deviceToken(在我的情况下是installId)连接到我的userAgent:这也很好用!即使生成错误,也会将installID插入userAgent。
MainActivity.java
deviceToken = ParseInstallation.getCurrentInstallation().getInstallationId();
webSettings.setUserAgentString(userAgent + " ||" + deviceToken);
我在代码中犯了什么错误吗?
谢谢
答案 0 :(得分:0)
请尝试以下方法:
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback()
{
@Override
public void done(ParseException e)
{
PushService.setDefaultPushCallback(Application.this, MainActivit.class);
}
});
答案 1 :(得分:0)
我记得,使用setDefaultPushCallback时不需要保存安装。尝试删除保存安装,看看它是否仍然存在。
setDefaultPushCallback会自动为您保存安装。不记得我发现它的位置,但在一些论坛上它被告知是行为。我想在第二次保存之后(没有第一次完成)会使安装处于错误状态,导致非致命错误消息。