十万火急!!!LeanCloud炸了
现象描述:( LeanCloud版本7.0.7)
用户登录成功后(首次调用了AVIMClient.open()方法,并且收到AVIMClientCallback回调),此时可以正常接收消息。退出应用程序后,再次打开应用,按道理讲,leancloud重连机制应该起作用了,实测证明,Android5.1上效果稍微好点,基本上能自动连接上leancloud并正常收发消息,但是Android 10上就不会自动连接成功,此时其他账号给Android10发送消息收不到,Android10发消息给其他账号,都会报错({"appCode":0,"code":999,"detailMessage":"Connection Lost"} 或者 {"appCode":0,"code":4105,"detailMessage":"SESSION_REQUIRED"})。重新发送失败消息后(此时主动调用了AVIMClient.open()方法),然后能收到别人刚刚发过来的消息,此时自己也可以正常发送消息。如果退到后台过一会再启动应用,又跟上述现象一样了,所以不知道leancloud最新版本是什么问题,导致Android高版本经常出现leancloud聊天连接不上,是LeanCloud连接有问题吗?求大神指导。
备注:leancloud所有配置都是正确的
if (BuildConfig.LOG_DEBUG) {
/*call before AVOSCloud.initialize()*/
AVOSCloud.setLogLevel(AVLogger.Level.DEBUG);
}
String appId = BuildConfig.LEANCLOUD_APPID;
String apiHost = BuildConfig.LEANCLOUD_API_HOST;
AVOSCloud.initializeSecurely(context, appId, apiHost);
/*Android 8.0:call after AVOSCloud.initialize with default notification channel */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = context.getPackageName() + ".leancloud";
PushService.setDefaultChannelId(context, channelId);
String appName = context.getResources().getString(R.string.app_name);
String notificationContent = appName + "正在运行";
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.mipmap.ic_app_logo)
.setContentTitle(notificationContent)
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
.build();
PushService.setForegroundMode(true, 0, notification);
}
/*push service*/
PushService.setAutoWakeUp(true);
PushService.setDefaultPushCallback(context, MainActivity.class);
/* LeanCloud Client monitor、Message monitor、Offline Message */
AVIMClient.setClientEventHandler(new IMClientEventHandler());
AVIMMessageManager.registerMessageHandler(AVIMTypedMessage.class, new MessageHandler(context));
AVIMMessageManager.setConversationEventHandler(new IMConversationEventHandler());
重新打开leancloud:(1)reconnect参数登录时传入了false;(2)重新启动应用时(Application中初始化),传入true,Android5.1调用AVIMClient.open()时AVIMClientCallback有回调,但是Android10调用AVIMClient.open()方法时AVIMClientCallback无回调无响应
AVIMClientOpenOption openOption = new AVIMClientOpenOption();
openOption.setReconnect(reconnect);
AVIMClient imClient = AVIMClient.getInstance(clientId, “Mobile”);
imClient.open(openOption, new AVIMClientCallback() {
@Override
public void done(AVIMClient avimClient, AVIMException e) {
if (e == null) {/*连接成功*/
showLog("===>open leancloud client successfully");
} else { /*连接失败*/
showLog("===>openClient with exception whose errorCode:" + e.getCode() + ",errorAppCode:" +
e.getAppCode() + ", errorInfo:" + e.getMessage());
}
if (clientCallback != null) {
clientCallback.done(avimClient, e);
}
}
});