Android ParseInstallation.getCurrentInstallation().saveInBackground();不起作用
我在iOS中创建了一个应用程序,它使用解析来存储数据,还使用解析推送来在用户之间传递消息。我现在正在将应用程序转换为Android,并尝试对两者使用相同的解析后端。我正在成功上传/下载数据,我甚至可以从Android用户向iOS用户发送消息,但我无法让我的Android设备接收消息。突出的问题似乎是我无法让安装正常工作。我正在从onCreate函数调用这段代码:Android ParseInstallation.getCurrentInstallation().saveInBackground();不起作用,android,ios,parse-platform,push-notification,Android,Ios,Parse Platform,Push Notification,我在iOS中创建了一个应用程序,它使用解析来存储数据,还使用解析推送来在用户之间传递消息。我现在正在将应用程序转换为Android,并尝试对两者使用相同的解析后端。我正在成功上传/下载数据,我甚至可以从Android用户向iOS用户发送消息,但我无法让我的Android设备接收消息。突出的问题似乎是我无法让安装正常工作。我正在从onCreate函数调用这段代码: Parse.enableLocalDatastore(this); Parse.initialize(this, "id1", "id
Parse.enableLocalDatastore(this);
Parse.initialize(this, "id1", "id2");
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
ParseInstallation.getCurrentInstallation().saveInBackground();
调用此代码后,我检查数据库中是否有新安装,但没有显示任何内容。似乎是
ParseInstallation.getCurrentInstallation().savenBackground()代码>没有做任何事情。我遗漏了什么吗?与给定设备上的安装相关联的对象在解析安装表中没有一行,这就是为什么会出现错误的原因,此问题有两种可能的解决方案:
- 卸载应用程序并重新安装(这是不可接受的
解决方案),或
- 手动清除应用程序解析缓存。查看如何执行的答案
那
在调用Parse.initialize之前必须调用此方法
public static boolean deleteInstallationCache(Context context) {
boolean deletedParseFolder = false;
File cacheDir = context.getCacheDir();
File parseApp = new File(cacheDir.getParent(),"app_Parse");
File installationId = new File(parseApp,"installationId");
File currentInstallation = new File(parseApp,"currentInstallation");
if(installationId.exists()) {
deletedParseFolder = deletedParseFolder || installationId.delete();
}
if(currentInstallation.exists()) {
deletedParseFolder = deletedParseFolder && currentInstallation.delete();
}
return deletedParseFolder;
}
或者,您可以使用包私有方法
ParseInstallation.clearCurrentInstallationFromDisk(上下文)
在libs文件夹中添加“bolts-android-x.x.x”lib。
您可以在Parse SDK zip文件中找到它在saveInBackground中放置一个回调,并检查您没有收到一个名为“未找到要更新的对象”的错误。谢谢,我执行了回调,收到一个错误:“未找到要更新的对象”。你知道我为什么会得到这个结果吗?与给定设备上的安装相关联的对象在parse installation表中没有一行,这就是为什么你会得到这个错误,这个问题有两种可能的解决方案:1。卸载应用程序并重新安装(这是不可接受的解决方案),或2。手动清除应用程序解析缓存。请参阅我调用此函数的方法的答案。文件变量都正确加载。然后,它输入第一个if语句并将“true”加载到deleteParseFolder中。它跳过第二个if语句。完成此操作后,我使用添加的回调调用了我的初始问题中的代码,但仍然得到“未找到要更新的对象”异常。我有几次没有异常,但该项仍然没有出现在安装数据库中。我确实在完全卸载/重新安装应用程序后,让Parse安装转到数据库。此方法返回异常java.lang.NoSuchMethodException:clearCurrentInstallationFromDisk[class android.content.Context]
public static void clearParseInstallation(Context context) {
try {
Method method = ParseInstallation.class.getDeclaredMethod("clearCurrentInstallationFromDisk", Context.class);
method.setAccessible(true);
method.invoke(null, context);
} catch (Exception e) {
Log.e(e);
}
}