pubnub设置不适用于android OS9 android java

问题描述 投票:0回答:1

我使用Java在android上安装了pubnub

并且在所有其他操作系统上,安装程序运行正常。但是在Android P上,attach侦听器始终会给出此错误-

  PNStatus(category=PNBadRequestCategory, errorData=PNErrorData(information=null, throwable=PubNubException(errormsg=CLEARTEXT communication to ps.pndsn.com not permitted by network security policy, pubnubError=PubNubError(errorCode=103, errorCodeExtended=0, errorObject=null, message=HTTP Error. Please check network connectivity. Please contact support with error details if issue persists., errorString=null), jso=null, response=null, statusCode=0)), error=true, statusCode=0, operation=PNSubscribeOperation, tlsEnabled=false, uuid=null, authKey=null, origin=null, clientRequest=null, affectedChannels=[5d67fb36f4f95718bf8ec310], affectedChannelGroups=[])

设置如下-

    PNConfiguration pnConfiguration = new PNConfiguration();
    pnConfiguration.setLogVerbosity(PNLogVerbosity.BODY);
    pnConfiguration.setPublishKey(getString(R.string.pubnub_publish_key));
    pnConfiguration.setSubscribeKey(getString(R.string.pubnub_subscribe_key));
    pnConfiguration.setSecure(false);
    pubnub = new PubNub(pnConfiguration);

然后我附加这样的听众

pubnub.addListener(new SubscribeCallback() {
@Override
public void status(PubNub pubnub, PNStatus status) {
    Log.e("Pubnub:- ", status.toString());
    switch (status.getOperation()) {
        // let's combine unsubscribe and subscribe handling for ease of use
        case PNSubscribeOperation:
        case PNUnsubscribeOperation:
            // note: subscribe statuses never have traditional
            // errors, they just have categories to represent the
            // different issues or successes that occur as part of subscribe
            switch (status.getCategory()) {
                case PNConnectedCategory:
                    // this is expected for a subscribe, this means there is no error or issue whatsoever
                case PNReconnectedCategory:
                    // this usually occurs if subscribe temporarily fails but reconnects. This means
                    // there was an error but there is no longer any issue
                case PNDisconnectedCategory:
                    // this is the expected category for an unsubscribe. This means there
                    // was no error in unsubscribing from everything
                case PNUnexpectedDisconnectCategory:
                    // this is usually an issue with the internet connection, this is an error, handle appropriately
                case PNAccessDeniedCategory:
                    // this means that PAM does allow this client to subscribe to this
                    // channel and channel group configuration. This is another explicit error
                default:
                    // More errors can be directly specified by creating explicit cases for other
                    // error categories of `PNStatusCategory` such as `PNTimeoutCategory` or `PNMalformedFilterExpressionCategory` or `PNDecryptionErrorCategory`
            }

        case PNHeartbeatOperation:
            // heartbeat operations can in fact have errors, so it is important to check first for an error.
            // For more information on how to configure heartbeat notifications through the status
            // PNObjectEventListener callback, consult <link to the PNCONFIGURATION heartbeart config>
            if (status.isError()) {
                // There was an error with the heartbeat operation, handle here
            } else {
                // heartbeat operation was successful
            }
        default: {
            // Encountered unknown status type
        }
    }
}

@Override
public void message(PubNub pubnub, PNMessageResult message) {
    String messagePublisher = message.getPublisher();
    System.out.println("Message publisher: " + messagePublisher);
    System.out.println("Message Payload: " + message.getMessage());
    System.out.println("Message Subscription: " + message.getSubscription());
    System.out.println("Message Channel: " + message.getChannel());
    System.out.println("Message timetoken: " + message.getTimetoken());
}

@Override
public void presence(PubNub pubnub, PNPresenceEventResult presence) {

}

@Override
public void signal(PubNub pubnub, PNSignalResult pnSignalResult) {
    System.out.println("Signal publisher: " + signal.getPublisher());
    System.out.println("Signal payload: " + signal.getMessage());
    System.out.println("Signal subscription: " + signal.getSubscription());
    System.out.println("Signal channel: " + signal.getChannel());
    System.out.println("Signal timetoken: " + signal.getTimetoken());
}

@Override
public void user(PubNub pubnub, PNUserResult pnUserResult) {
    // for Objects, this will trigger when:
    // . user updated
    // . user deleted
    PNUser pnUser = pnUserResult.getUser(); // the user for which the event applies to
    pnUserResult.getEvent(); // the event name
}

@Override
public void space(PubNub pubnub, PNSpaceResult pnSpaceResult) {
    // for Objects, this will trigger when:
    // . space updated
    // . space deleted
    PNSpace pnSpace = pnSpaceResult.getSpace(); // the space for which the event applies to
    pnSpaceResult.getEvent(); // the event name
}

@Override
public void membership(PubNub pubnub, PNMembershipResult pnMembershipResult) {
    // for Objects, this will trigger when:
    // . user added to a space
    // . user removed from a space
    // . membership updated on a space
    JsonElement data = pnMembershipResult.getData(); // membership data for which the event applies to
    pnMembershipResult.getEvent(); // the event name
}

@Override
public void messageAction(PubNub pubnub, PNMessageActionResult pnActionResult) {
    PNMessageAction pnMessageAction = pnActionResult.getAction();
    System.out.println("Message action type: " + pnMessageAction.getType());
    System.out.println("Message action value: " + pnMessageAction.getValue());
    System.out.println("Message action uuid: " + pnMessageAction.getUuid());
    System.out.println("Message action actionTimetoken: " + pnMessageAction.getActionTimetoken());
    System.out.println("Message action messageTimetoken: " + pnMessageAction.getMessageTimetoken());]

    System.out.println("Message action subscription: " + pnActionResult.getSubscription());
    System.out.println("Message action channel: " + pnActionResult.getChannel());
    System.out.println("Message action timetoken: " + pnActionResult.getTimetoken());
}

});

就像我说的那样,它在9以外的其他操作系统上都可以正常工作,并且我使用的是pubnub的最新版本,实际上我已升级到最新版本,并且上述错误是相同的。

[我注意到了其他事情,我在调试器中看到的消息仅在android版本9中运行时才显示。

  isWhitelistProcess - Process is Whitelisted

我搜索了该消息,发现它是无害的警告消息。

android pubnub
1个回答
0
投票

启用TLS(SSL)可解决此错误:pnConfiguration.setSecure(true);

原因已在another Stack Overflow thread中回答。它不是特定于PubNub,而是因为您在PubNub中禁用了TLS(SSL),所以它在错误中显式调用了PubNub域。

© www.soinside.com 2019 - 2024. All rights reserved.