easygcm


Source link: https://github.com/inloop/easygcm

easygcm

Android Library for easy GCM integration. Including push notifications sender task for Gradle.

This library is based on sample client code provided by Android documentation at http://developer.android.com/google/gcm/client.html and https://code.google.com/p/gcm/

It includes all the common code from the sample including AndroidManifest.xml that is automatically merged into your application. Also content of sample's DemoActivity is included in this library extracted in GcmHelper class. This library further improves original sample client in several ways, see changelog.

How to use:

  • The project uses Google Play Services, so make sure you have:

  • classpath 'com.google.gms:google-services:1.5.0' in your project root gradle file

  • apply plugin: 'com.google.gms.google-services' in your module gradle file

  • compile 'com.google.android.gms:play-services-gcm:8.3.0' in your module gradle file dependencies

  • Add this to your build.gradle: compile 'eu.inloop:easygcm:1.6.2@aar'

  • In your Application implement GcmListener interface with two methods:

    • onMessage()
    • sendRegistrationIdToBackend()

Note: Both methods are executed asynchronously in background thread and the wake lock is held until the method is executed. Don't start other asynchronous tasks here unless needed - the wake lock would be released and the tasks would not be guaranteed to run. Put the blocking code right into these methods.

  • In your MainActivity onCreate(), call EasyGcm.init(this);

  • Define GCM Sender ID adding google-service.json configuration and setting up Google Services Gradle plugin as described in Implementing GCM Client on Android

  • Alternatively, instead of being implemented by the Application class, you can have your own instance of GcmListener and set it in the application with EasyGcm.setGcmListener(GcmListener listener)

If you need GET_ACCOUNTS permission, add this to you application's manifest:

<uses-permission
  android:name="android.permission.GET_ACCOUNTS"
  tools:remove="android:maxSdkVersion"/> 

If you want to access the registrationId after the registration has finished, you can use EasyGcm.isRegistered(Context context), EasyGcm.getRegistrationId(Context context) or for convenience EasyGcm.resendRegistrationIdToBackend(Context context) (returns null if registrationId does not exist).

That's it. You might also want to use Gradle task for sending push notifications to your device:

  • add Gradle dependency to buildscript section: classpath 'eu.inloop:easygcm-tasks:1.3.0'
  • add following code to your build.gradle and edit push notification data, apiKey and registration ID
task push(type: eu.inloop.easygcm.PushTask) {

  data = '{
"myMessage":"Hello World"
}
'
  apiKey = 'AIzaSyDt0uzm74Un5qsoEyQcvE-5lhDB3n3m9XX' // Server API Key
  registrationIds = [

 'mt4gNCjtlRs:APA91bHiu_7X_CzA_IbSk9FiR_wk9b6sIvAuR6t-zoE5ujSx0D5Obql5dZiQ9DrEK8YsJm4lBr2nNLKWGRKSr2GZJSgdm_jxOWO4nBCE2QYNzJTS2bCTPRgrIH7cra0t1BEU7g2dwnYY'
  ] 
}
  • call ./gradlew push

How to build locally:

So far, it is not possible to use project dependencies in Gradle's buildscript section (needed for our plugin). That means you have to build the library first (and install in local Maven repo) and just then build the sample application.

./gradlew clean uploadArchives ./gradlew -p easygcm-sample clean assembleDebug 

Resources

A Kotlin library for reactive and boilerplate-free Shared Preferences in Android. With KPreferences you can use Kotlin's marvelous delegate concept to easily use Android's Shared Preferences. Features:

  • Boilerplate-free: Use SharedPreferences properties with one line and without edit, apply or ... boilerplate codes
  • Reactive: Use observables to listen for SharedPreferences changes without any memory leak
  • Custom types: You are not limited to a set of limited types that can be saved to the SharedPreferences .

An Android image picker and cropper library.

Android - FilePickerFilter Library.

Simple text counter animation. You need to set from number and to number! And this library will create animation. Also you can use different modes.

CameraKit is an extraordinarily easy to use utility to work with the infamous Android Camera and Camera2 APIs.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes