Android quick start
Getting started with Channels is very easy. However, if you have any questions get in touch. This guide uses the pusher-websocket-java library and a selection of Server API libraries. We also have a guide for our JavaScript client.
Create an account, and make a note of your app_id
, app_key
, app_secret
and app_cluster
.
In your build.gradle
script for your application module, add the library as a dependency:
1 2 3
dependencies { compile 'com.pusher:pusher-java-client:2.2.1' }
Add the following as a child of dependencies
in your pom.xml
:
1 2 3 4 5
<dependency> <groupId>com.pusher</groupId> <artifactId>pusher-java-client</artifactId> <version>2.2.1</version> </dependency>
1 2 3 4 5 6 7 8
import com.pusher.client.Pusher; ... PusherOptions options = new PusherOptions(); options.setCluster("APP_CLUSTER"); Pusher pusher = new Pusher("APP_KEY", options); pusher.connect();
See more about configuring the java library
1 2 3 4
import com.pusher.client.channel.Channel; ... Channel channel = pusher.subscribe("my-channel");
Once you have created an instance of Channel
, you can set up event bindings.
1 2 3 4 5 6 7 8 9
import com.pusher.client.channel.SubscriptionEventListener; ... channel.bind("my-event", new SubscriptionEventListener() { @Override public void onEvent(String channelName, String eventName, String data) { System.out.println(data); } });
In the examples below we trigger an event named my-event
to Channels on a channel called my-channel
. For each example below a server library deals with the server communication.
- Rails
- Ruby
- PHP
- Node.js
- ASP.NET MVC
- Python
- Go
- Java
- Pusher CLI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# First, run 'gem install pusher' require 'pusher' pusher = Pusher::Client.new( app_id: 'APP_ID', key: 'APP_KEY', secret: 'APP_SECRET', cluster: 'APP_CLUSTER' ) class HelloWorldController < ApplicationController def hello_world pusher.trigger('my-channel', 'my-event', {:message => 'hello world'}) end end
If there isn’t an example in a language that you are familiar with then have a look on our server libraries page to see if anyone has created one in your language.
Find out about all the cool stuff you can do withchannels. Learn how to exclude event recipients when publishing events.