Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

devsu/android-push-client

Repository files navigation

GCM Push Client [DEPRECATED]

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!

publicclassMyApplicationextendsApplication{@OverridepublicvoidonCreate(){super.onCreate(); ... // FCM is selected by defaultFirebaseApp.initialize(this); PushClient.initialize(this, "MY_GCM_ID"); // Or GCMPushClient.initialize(this, Provider.GCM, "MY_GCM_ID")} }

InitCallback

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

publicclassMyApplicationextendsApplication{@OverridepublicvoidonCreate(){super.onCreate(); ... PushClient.initialize(this, "MY_GCM_ID", newInitCallback(){@OverridepublicvoidonSuccess(StringregistrationId, booleanhasBeenUpdated){Log.i(TAG, "This is my registrationId: " + registrationId)} @OverridepublicvoidonError(Throwablethrowable){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:

publicclassToastDelegateimplementsPushDelegate{privateStringmMessageKey; privateContextmContext; publicToastDelegate(Contextcontext){this.mContext = context} ... @OverridepublicvoidhandleNotification(Contextcontext, Bundleextras){Stringmessage = extras.getString(mMessageKey, null); if (message == null){return} Toast.makeText(mContext, message, Toast.LENGTH_LONG).show()} }

Initialize it!

publicclassMyApplicationextendsApplication{@OverridepublicvoidonCreate(){super.onCreate(); ... PushClient.initialize(this, Provider.GCM, "MY_GCM_ID", newToastDelegate(this))} }

Customizing SimpleNotificationDelegate

You can change every aspect of your Push Notification!

publicclassMyApplicationextendsApplication{@OverridepublicvoidonCreate(){super.onCreate(); ... PushClient.initialize(this, Provider.FCM, "MY_GCM_ID"); SimpleNotificationDelegatedelegate = (SimpleNotificationDelegate) PushClient.getDelegate(); // Change the large icondelegate.setLargeIconDrawableResId(R.drawable.ic_icon_large); // Change the small icondelegate.setSmallIconDrawableResId(R.drawable.ic_icon_small); // Change the Activity that opens on Notification clickdelegate.setDefaultActivity(MainActivity.class); // Change title and message keysdelegate.setTitleKey("TITLE_KEY"); delegate.setMessageKey("MESSAGE_KEY"); // Change the vibration patterndelegate.setVibrationPattern(newlong[]{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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages