GCM Push Client

Library that allows you to easily receive GCM/FCM Push Messages on Android.

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.devsu
ArtifactId

ArtifactId

pushclient
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

aar
Description

Description

GCM Push Client
Library that allows you to easily receive GCM/FCM Push Messages on Android.
Project URL

Project URL

https://github.com/devsu/gcm-push-client
Source Code Management

Source Code Management

https://github.com/devsu/gcm-push-client

Download pushclient

How to add to project

<!-- https://jarcasting.com/artifacts/com.devsu/pushclient/ -->
<dependency>
    <groupId>com.devsu</groupId>
    <artifactId>pushclient</artifactId>
    <version>1.1.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.devsu/pushclient/
implementation 'com.devsu:pushclient:1.1.1'
// https://jarcasting.com/artifacts/com.devsu/pushclient/
implementation ("com.devsu:pushclient:1.1.1")
'com.devsu:pushclient:aar:1.1.1'
<dependency org="com.devsu" name="pushclient" rev="1.1.1">
  <artifact name="pushclient" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.devsu', module='pushclient', version='1.1.1')
)
libraryDependencies += "com.devsu" % "pushclient" % "1.1.1"
[com.devsu/pushclient "1.1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 24.2.0
com.google.android.gms » play-services-gcm jar 9.4.0
com.google.firebase » firebase-messaging jar 9.0.0

Project Modules

There are no modules declared in this project.

GCM Push Client

GCM Push Client is an Android library that allows receiving Push Messages, without dealing with the hassle of making your Receiver, GCM Registration Service and all of that fun stuff.

Overview

Using GCM Push Client is very simple. You can import GCM Push Client on your build.gradle file (using jCenter or Maven Central):

    // Remember to add your GCM Play Services dependency!
    compile 'com.google.android.gms:play-services-gcm:11.4.2'

    // Or if you're using FCM, import the FCM dependency!
    compile 'com.google.firebase:firebase-messaging:11.4.2'

    compile 'com.devsu:pushclient:1.1.2'

Add the com.google.gms.google-services plugin, and then, initialize the library on your Application. That's it!

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ...

        // FCM is selected by default
        FirebaseApp.initialize(this);
        PushClient.initialize(this, "MY_GCM_ID");

        // Or GCM
        PushClient.initialize(this, Provider.GCM, "MY_GCM_ID");
    }
}

InitCallback

Customize your client's behavior when retrieving your GCM registration ID.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ...
        PushClient.initialize(this, "MY_GCM_ID", new InitCallback() {
            @Override
            public void onSuccess(String registrationId, boolean hasBeenUpdated) {
                Log.i(TAG, "This is my registrationId: " + registrationId);
            }

            @Override
            public void onError(Throwable throwable) {
                Log.e(TAG, "An error occurred :(");
            }
        });
    }
}

Customizing

Using the delegation pattern, GCM Push Client is easy to customize. Simply create your own class that implements PushDelegate, or change the default settings on SimpleNotificationDelegate.

Custom Delegate

Create your own Delegate Class:

public class ToastDelegate implements PushDelegate {

    private String mMessageKey;
    private Context mContext;

    public ToastDelegate(Context context) {
        this.mContext = context;
    }
    ...

    @Override
    public void handleNotification(Context context, Bundle extras) {
        String message = extras.getString(mMessageKey, null);
        if (message == null) {
            return;
        }
        Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
    }
}

Initialize it!

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ...
        PushClient.initialize(this, Provider.GCM, "MY_GCM_ID", new ToastDelegate(this));
    }
}

Customizing SimpleNotificationDelegate

You can change every aspect of your Push Notification!

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ...
        PushClient.initialize(this, Provider.FCM, "MY_GCM_ID");
        SimpleNotificationDelegate delegate = (SimpleNotificationDelegate) PushClient.getDelegate();

        // Change the large icon
        delegate.setLargeIconDrawableResId(R.drawable.ic_icon_large);

        // Change the small icon
        delegate.setSmallIconDrawableResId(R.drawable.ic_icon_small);

        // Change the Activity that opens on Notification click
        delegate.setDefaultActivity(MainActivity.class);

        // Change title and message keys
        delegate.setTitleKey("TITLE_KEY");
        delegate.setMessageKey("MESSAGE_KEY");

        // Change the vibration pattern
        delegate.setVibrationPattern(new long[] {0, 500, 200, 1000});

        // AND MUCH MORE!
    }
}

Authors

Feel free to contact Alvaro López at [email protected]!

License

Copyright 2015 Devsu Software

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

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.

com.devsu

Devsu

Versions

Version
1.1.1
1.1.0
1.0.0