Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple pusher implementation and activity for Android!

This branch is 0 commits ahead and 0 commits behind stable-0.3

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 library
Octocat-spinner-32 sample
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
README.md

Android_Pusher

This code provides a simple implementation allowing for an Android 1.6+ app to receive realtime events from http://pusher.com

This project makes use of a slightly modified Weberknect, available at http://v.google.com/p/weberknecht/

Special thanks to http://natronbaxter.com/ and http://mokasocial.com for giving me the opportunity to write and open source this!

This project is under the Apache License, Version 2.0! http://www.apache.org/licenses/LICENSE-2.0.html

To get started receiving events from your Pusher account:

  • Clone this repository locally
  • Sign up for an account at http://pusher.com
  • Download Eclipse and the Android SDK from http://developer.android.com/sdk/index.html
  • Open the project in Eclipse (Using File > New Project > From Existing Source)
  • Open PusherSampleActivity.java, and find the constants PUSHER_APP_KEY and PUSHER_CHANNEL_1
  • Change these constants to your assigned Pusher app key and your first channel.
  • Run the application on a device or emulator, and send messages from your Pusher console.
  • To add more channels, duplicate the existing code that handles inbound.
  • To handle multiple event types, modify the Activity's mHandler.handleMessage() function, checking the "type" string of the incoming event.

Quick Example of the new API:

Pusher pusher = new Pusher( "pusher_key" );
final Channel channel = pusher.subscribe( "chat-channel" );
channel.bind( "new_message" , new PusherCallback() {
  public void onEvent(JSONObject eventData) {
    Log.d( "Pusher", "Received " + eventData.toString() + " for event 'new_message' on channel " + channel.name );
    myTextField.setText( eventData.getString("content") );
  }
});

you can bind to any event of a channel as long as you are subscribed to it:

channel.bindAll(new PusherCallback() {
  public void onEvent(String eventName, JSONObject eventData) {
    Log.d( "Pusher", "Received " + eventData.toString() + " for event '" + eventName +"' on channel " + channel.name );
  }
});

bind() and bindAll() also work on the pusher instance, in order to retrieve events from all channels

pusher.bindAll(new PusherCallback() {
  public void onEvent(String eventName, JSONObject eventData) {
    Log.d( "Pusher", "I will show up on any event on any subscribed channel" );
  }
});

For support, visit http://pusher.com/support.

Something went wrong with that request. Please try again.