我正在使用pubnub Adnroid SDK 4.20.0,当我尝试启动Subscribecallback侦听器时,它总是进入PNTimeoutCategory。我的初始化代码如下。
private void InitializePubnub()
{
PNConfiguration pnConfiguration = new PNConfiguration();
pnConfiguration.setReconnectionPolicy(PNReconnectionPolicy.LINEAR);
pnConfiguration.setSubscribeKey(GlobalClass.PUBNUB_SUBSCRIBE_KEY);
pnConfiguration.setPublishKey(GlobalClass.PUBNUB_PUBLISH_KEY);
pnConfiguration.setSecure(false);
if (pubnub == null)
{
pubnub = new PubNub(pnConfiguration);
}
}
我正在这样创建我的订户回调:
SubscribeCallback subscribeCallback;
public void PubnubListener() {
if (subscribeCallback == null) {
subscribeCallback = new SubscribeCallback() {
@Override
public void status(PubNub pubnub, PNStatus status) {
if (status.getCategory() == PNStatusCategory.PNConnectedCategory){
Log.d("TAG", "Category: " + PNStatusCategory.PNConnectedCategory);
}else if (status.getCategory() == PNStatusCategory.PNReconnectedCategory) {
Log.d("TAG", "Category: " + PNStatusCategory.PNReconnectedCategory);
}
else if (status.getCategory() == PNStatusCategory.PNDecryptionErrorCategory) {
Log.d("TAG", "Category: " + PNStatusCategory.PNDecryptionErrorCategory);
} else if (status.getCategory() == PNStatusCategory.PNUnexpectedDisconnectCategory) {
pubnub.reconnect();
} else if (status.getCategory() == PNStatusCategory.PNTimeoutCategory) {
// do some magic and call reconnect when ready
pubnub.reconnect();
} else {
Log.d("TAG", status.getErrorData().getInformation());
}
}
@Override
public void message(PubNub pubnub, PNMessageResult message) {
}
@Override
public void presence(PubNub pubnub, PNPresenceEventResult presence) {
}
};
PubNubClass.getInstance().pubnub.addListener(subscribeCallback);
}
}