Android GCM Library


v1.0.3 (Dec 3, 2016)
Apr 14, 2016
Dec 3, 2016 (Retired)
Abhishek Nandi (Atrix1987)
Abhishek Nandi (Atrix1987)
Umang Chamaria (umangmoe)
Source code

Android GCM Library

A library which helps you register Google Cloud Messaging tokens and listen for GCM messages. It can be used to attach multiple providers and seamlessly deliver data and token to all the listeners. This library is very helpful for those you use multiple push notification provider.

Salient Features

  • Takes care of GCM Registration
  • Token rotation, updates
  • Provides callbacks for listening to registration changes
  • Provides callbacks for GCM message callbacks

For example, A lot of apps use multiple push providers. This library helps them to maintain a clean code and also loosely couple the providers still providing support for all

Adding the library as a dependency

Add the following your build.gradle file

compile 'com.nandi:gcm-lib:1.0.3'

Supports Play Services GCM 10.0.1

How to use ?

Implementing a Registration Listener

public class CustomRegistrationListener implements GcmHelper.GcmRegistrationListener{

  @Override public void onTokenAvailable(Context context, String token, boolean updated) {
    //TODO do something with the token

  @Override public void onTokenDeleted(Context context) {
    //TODO delete the token

Implementing the Message Listener

public class CustomMessageReceivedListener implements GcmHelper.GcmMessageListener {

  @Override public void onMessageReceived(Context context, String from, Bundle data) {
    //TODO start your service or do something else

  @Override public boolean canHandleMessage(Bundle data){
    //TODO check the bundle to see if the listener can handle payload
    return false;

Now in your application class onCreate method following:

        .addRegistrationCallback(getApplicationContext(), new CustomRegistrationListener(), true)
        .addOnMessageReceivedCallback(new CustomMessageReceivedListener())

setAuthorizedEntity is the sender id or the Google Project number

Minimum Requirements Google Play Services GCM library 7.5

As seen here

GCM register() is deprecated starting May 28, 2015. New app development should use the Instance ID API to handle the creation, rotation, and updating of registration tokens.


GCMLib is Apache Licence.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.