Implementing Android Pusher Request Object in HttpAuthorizer

I am new to Pusher. I have successfully implemented a public channel subscription in my application. I am now stuck with subscribing to a private android channel.

We have to pass the request body parameters to our server endpoint. In my iOS app, we create a custom authorizer to send the request body to PusherOption. But in Android there are only 2 options for sending parameters to PusherOptions like setHeaders () and setQueryStringParameters ().

I need to send the following body with a url:

["data": ["socket_id": SOCKET_ID, "user_id": USER_ID, "channel": "private-CHANNEL_NAME"]]

      

I am currently getting an exception in onAuthenticationFailure as [com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: MY ENDPOINT URL].

My current Android code looks like this:

public static void subscribePrivateChannel(final String channelName, final String userId, final String authKey) {
    final HttpAuthorizer authorizer = new HttpAuthorizer(MY_ENDPOINT_URL);
    PusherOptions options = new PusherOptions().setEncrypted(true).setAuthorizer(authorizer);
    final Pusher pusher = new Pusher(Config.PUSHER_APP_KEY, options);

    pusher.connect(new ConnectionEventListener() {
        @Override
        public void onConnectionStateChange(ConnectionStateChange connectionStateChange) {
            if (connectionStateChange.getCurrentState().toString().equalsIgnoreCase("CONNECTED")) {
                String socketId = pusher.getConnection().getSocketId();
                HashMap<String, String> parameters = new HashMap<>();
                parameters.put("socket_id", socketId);
                parameters.put("channel", channelName);
                parameters.put("user_id", userId);
                authorizer.setQueryStringParameters(parameters);

                pusher.subscribePrivate(channelName, new PrivateChannelEventListener() {
                    @Override
                    public void onAuthenticationFailure(String s, Exception e) {
                        Log.d(TAG, "onAuthenticationFailure() called with: s = [" + s + "], e = [" + e + "]");
                    }

                    @Override
                    public void onSubscriptionSucceeded(String s) {
                        Log.d(TAG, "onSubscriptionSucceeded() called with: s = [" + s + "]");
                    }

                    @Override
                    public void onEvent(String s, String s1, String s2) {
                        Log.d(TAG, "onEvent() called with: s = [" + s + "], s1 = [" + s1 + "], s2 = [" + s2 + "]");
                    }
                });
            }
        }

        @Override
        public void onError(String s, String s1, Exception e) {
            Log.d(TAG, "onError() called with: s = [" + s + "], s1 = [" + s1 + "], e = [" + e + "]");
        }
    });
}

      

0
android authorization pusher


source to share


No one has answered this question yet

See similar questions:

3
Pusher on Android

or similar:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
1296
Reloading activity on android rotation
1152
Difference between gravity and layout_gravity on Android



All Articles
Loading...
X
Show
Funny
Dev
Pics