Set up Pulses in your Android application
build.gradle
implementation 'com.pusher:pusher-java-client:2.3.1'
import com.pusher.client.Pusher; import com.pusher.client.PusherOptions; PusherOptions options = new PusherOptions() .setHost("ws.pulses.cloud") .setEncrypted(true); Pusher pusher = new Pusher("YOUR_APP_KEY", options);
pusher.connect(new ConnectionEventListener() { @Override public void onConnectionStateChange(ConnectionStateChange change) { System.out.println("State changed to " + change.getCurrentState() + " from " + change.getPreviousState()); } @Override public void onError(String message, String code, Exception e) { System.out.println("There was a problem connecting!"); } }, ConnectionState.ALL);
com.pusher.client.channel.Channel channel = pusher.subscribe("channel-name");
channel.bind("event-name", new SubscriptionEventListener() { @Override public void onEvent(String channel, String event, String data) { System.out.println("Received event with data: " + data); } });
trigger
// First, run 'npm install pusher' const Pusher = require('pusher'); const pusher = new Pusher('YOUR_APP_KEY', { wsHost: 'ws.pulses.cloud', encrypted: true, disableStats: true, enabledTransports: ['ws', 'wss'], cluster: 'pulses' }); pusher.trigger('channel-name', 'event-name', { message: 'Hello World' });
pusher.unsubscribe("channel-name");
pusher.disconnect();
Was this page helpful?