Android quick start

Getting started with Pusher 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.

Get your free API keys

Create an account, and make a note of your app_id, app_key, app_secret and app_cluster.

Install the library


In your build.gradle script for your application module, add the library as a dependency:

dependencies {
    compile 'com.pusher:pusher-java-client:1.4.0'


The pusher-websocket-java library is also available in Maven Central. Add a dependency element as a child of dependencies with the following in pom.xml:


Create a connection

import com.pusher.client.Pusher;
PusherOptions options = new PusherOptions();

Pusher pusher = new Pusher("APP_KEY", options);

See more about configuring the java library

Subscribe to a public channel


Channel channel = pusher.subscribe("my-channel");

Listen for events

Once you have created an instance of Channel, you can set up event bindings.


channel.bind("my-event", new SubscriptionEventListener() {
    public void onEvent(String channelName, String eventName, final String data) {

Trigger events from your server

In the examples below we trigger an event named my_event to Pusher on a channel called test_channel. For each example below a server library deals with the server communication.

require 'pusher'

pusher_client =
  app_id: 'APP_ID',
  key: 'APP_KEY',
  secret: 'APP_SECRET',
  cluster: 'APP_CLUSTER'

class HelloWorldController < ApplicationController
  def hello_world
    pusher_client.trigger('test_channel', 'my_event', {:message => 'hello world'})
require 'pusher'

pusher_client =
  app_id: 'APP_ID',
  key: 'APP_KEY',
  secret: 'APP_SECRET',
  cluster: 'APP_CLUSTER'

pusher_client.trigger('test_channel', 'my_event', {:message => 'hello world'})

$pusher = new Pusher("APP_KEY", "APP_SECRET", "APP_ID", array('cluster' => 'APP_CLUSTER'));

$pusher->trigger('test_channel', 'my_event', array('message' => 'hello world'));
var Pusher = require('pusher');

var pusher = new Pusher({
  appId: 'APP_ID',
  key: 'APP_KEY',
  secret: 'APP_SECRET',
  cluster: 'APP_CLUSTER'

pusher.trigger('test_channel', 'my_event', {"message": "hello world"});
using PusherServer;
using System.Web.Mvc;
using System.Net;
using Your.Config;

public class HelloWorldController : Controller {
  public async Task<ActionResult> HelloWorld() {
    var options = new PusherOptions();
    options.Cluster = 'APP_CLUSTER';

    var pusher = new Pusher('APP_ID', 'APP_KEY', 'APP_SECRET', options);
    var result = await pusher.TriggerAsync("test_channel", "my_event", new { message = "hello world" });
    return new HttpStatusCodeResult((int)HttpStatusCode.OK);
from pusher import Pusher

pusher = Pusher(

pusher.trigger(u'test_channel', u'my_event', {u'message': u'hello world'})
package main

import ""

func main(){

  client := pusher.Client{
    AppId: "APP_ID",
    Key: "APP_KEY",
    Secret: "APP_SECRET",
    Cluster: "APP_CLUSTER",

  data := map[string]string{"message": "hello world"}
  client.Trigger("test_channel", "my_event", data)

Pusher pusher = new Pusher("APP_ID", "APP_KEY", "APP_SECRET");

pusher.trigger("test_channel", "my_event", Collections.singletonMap("message", "Hello World"));

Note! If you created your app in a different cluster to the default us-east-1, you must configure the cluster option as well. See how.

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.

Where next?

Find out about all the cool stuff you can do with channels, Investigate the JavaScript client library or learn how to excluding event recipients when publishing events.

Have you tried using the search to find what you’re after? If you still have a question then get in touch with us and let us help you out.