添加以下代码.
提前致谢
final httpAuthorizer authorizer = new httpAuthorizer(myurl); authorizer.setheaders(getMapAuthorizationheaders()); PusherOptions options = new PusherOptions().setAuthorizer(authorizer); final Pusher pusher = new Pusher("pusher_key",options); pusher.connect(new com.pusher.clIEnt.connection.ConnectionEventListener() { @OverrIDe public voID onConnectionStateChange(ConnectionStateChange connectionStateChange) { Log.e("connectionStateChange",connectionStateChange.getCurrentState().toString()); if (connectionStateChange.getCurrentState() == ConnectionState.CONNECTED) { SOCKET_ID = pusher.getConnection().getSocketID(); Log.e("SOCKET_ID",""+SOCKET_ID); Channel channel = pusher.subscribePrivate(PUSH_CHANNEL,new PrivateChannelEventListener() { @OverrIDe public voID onAuthenticationFailure(String s,Exception e) { Log.e("PUSHER","Channel subscription authorization Failed"); } @OverrIDe public voID onSubscriptionSucceeded(String s) { Log.e("PUSHER","Channel subscription authorization succeeded"); } @OverrIDe public voID onEvent(String s,String s2,String s3) { Log.e("PUSHER","An event with name " + s2 + " was delivered!!"); } },"my-event"); } } @OverrIDe public voID onError(String s,String s1,Exception e) { } });public static HashMap<String,String> getMapAuthorizationheaders() {try { HashMap<String,String> authheader = new HashMap<>(); authheader.put("headerKey1","headerValue1"); authheader.put("headerKey2","headerValue2"); return authheader;} catch (Exception e) { return null;}
}
解决方法 我可以假设你把“pusher_key”放在哪里,你刚刚在这里添加了这个用于安全目的,在你的应用程序中你实际上是在使用你的密钥吗?除此之外,你在哪里定义PUSH_CHANNEL:pusher.subscribePrivate(PUSH_CHANNEL,
总结以上是内存溢出为你收集整理的Android Pusher未连接到私人频道全部内容,希望文章能够帮你解决Android Pusher未连接到私人频道所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)