Skip to content

Asynchronous Google Cloud Messaging (GCM) Library

Notifications You must be signed in to change notification settings

woosttech/gcm-sender-async

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gcm-sender-async

An asynchronous HTTP library for Google Cloud Messaging.

Google provides a library for GCM (gcm-server), but it has a synchronous interface, along with an implementation that leaves something to be desired.

This is asynchronous, backed by Apache HttpAsyncClient, automatically handles asynchronous retries with backoff, simple to use, and fast.

Installing

Add to your pom:

<dependency>
  <groupId>org.whispersystems</groupId>
  <artifactId>gcm-sender-async</artifactId>
  <version>(latest version here)</version>
</dependency>

Using

String apiKey = "<myGcmApiKey>";
Sender sender = new Sender(apiKey);

ListenableFuture<Result> future = sender.send(Message.newBuilder()
                                                     .withDestination("<registration_id>")
                                                     .withDataPart("message", "hello world!");

Futures.addCallback(future, new FutureCallback<Result>() {
  @Override
  public void onSuccess(Result result) {
    if (result.isSuccess()) {
      // Maybe do something with result.getMessageId()
    } else {
      // Maybe do something with result.getError(), or check result.isUnregistered, etc..
    }
  }

  @Override
  public void onFailure(Throwable throwable) {
    // Handle network failure or server 500
  }
}

License

Copyright 2015 Open Whisper Systems

Licensed under the AGPLv3: https://www.gnu.org/licenses/agpl-3.0.html

About

Asynchronous Google Cloud Messaging (GCM) Library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%