OPFPush


Source link: https://github.com/onepf/OPFPush

OPFPush

OPFPush is an open source library which provides an easy way for developers to integrate android push notifications into their apps.

Currently OPFPush supports the following push providers: Google Cloud Messaging, Nokia Notification Push, Amazon Device Messaging and provides possibility to use the system push provider for a specific device.

How To Use

Add dependencies

The main dependencies are the opfmaps module and the OPFUtils library:

compile 'org.onepf:opfpush:0.3.1@aar' compile 'org.onepf:opfutils:0.1.25'

Then you have to add at least one map provider dependency.

GCM Provider:

compile 'org.onepf:opfpush-gcm:0.3.1@aar' compile 'com.google.android.gms:play-services:7.8.0'

ADM Push Provider:

compile 'org.onepf:opfpush-adm:0.3.1@aar' provided 'com.amazon:amazon-device-messaging:1.0.1'

Nokia Push Provider:

compile 'org.onepf:opfpush-nokia:0.3.1@aar' compile 'com.nokia:push:1.0'

NOTE: If you use ADMProvider or/and NokiaPushProvider you have to add the following repo which hosts amazon-device-messaging.jar and nokia-push.jar:

allprojects {

repositories {

  ...
  // third-party dependencies
  maven {
 url 'https://raw.githubusercontent.com/onepf/OPF-mvn-repo/master/' 
}

}
 
}

Update AndroidManfest.xml

Add permissions and receivers required for each used Push Provider:

<!--gcm permissions--> <uses-permission android:name="${
applicationId
}
.permission.C2D_MESSAGE" /> <permission
 android:name="${
applicationId
}
.permission.C2D_MESSAGE"
 android:protectionLevel="signature" />
  <!--adm permissions--> <permission android:name="${
applicationId
}
.permission.RECEIVE_ADM_MESSAGE" /> <uses-permission
 android:name="${
applicationId
}
.permission.RECEIVE_ADM_MESSAGE"
 android:protectionLevel="signature" />
  <!--nokia--> <!--The same as for gcm-->
  <application>
  <!--gcm receiver-->
 <receiver

 android:name="com.google.android.gms.gcm.GcmReceiver"

 android:exported="true"

 android:permission="com.google.android.c2dm.permission.SEND">

 <intent-filter>

 <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

 <action android:name="com.google.android.c2dm.intent.RECEIVE"/>

 <category android:name="${
applicationId
}
"/>

 </intent-filter>
 </receiver>

  <!--adm receiver-->
 <receiver

 android:name="org.onepf.opfpush.adm.ADMReceiver"

 android:permission="com.amazon.device.messaging.permission.SEND">

  <intent-filter>

 <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />

 <action android:name="com.amazon.device.messaging.intent.RECEIVE" />

  <category android:name="${
applicationId
}
" />

 </intent-filter>
 </receiver>

  <!--nokia receiver-->
 <receiver

 android:name="org.onepf.opfpush.nokia.NokiaNotificationsReceiver"

 android:permission="com.nokia.pushnotifications.permission.SEND">

  <intent-filter>

 <action android:name="com.nokia.pushnotifications.intent.RECEIVE" />

 <action android:name="com.nokia.pushnotifications.intent.REGISTRATION" />

  <category android:name="${
applicationId
}
" />

 </intent-filter>
 </receiver>  </application>

Initialization

To setup OPFPush add the following piece of code to your Application.onCreate() method:

public class MyApplication extends Application {

  @Override
 public void onCreate() {

 super.onCreate();

 OPFLog.setEnabled(BuildConfig.DEBUG, true);
 //Optional. It enables debug logs of the OPFMaps library in the debug build of your apk.

  final Configuration configuration = new Configuration.Builder()

 .addProviders(new GCMProvider(this, GCM_SENDER_ID), new ADMProvider(this), new NokiaNotificationsProvider(this, NOKIA_SENDER_ID)) //Add all providers. The priority of the providers corresponds to the order in which they were added.

 .setSelectSystemPreferred(true) //If you set true, the system push provider will get the highest priority. Default value is false.

 .setEventListener(new PushEventListener(this)) //An implementation of EventListener interface.

 .build();

  OPFPush.init(this, configuration);
 //Init OPFPush using the created Configuration object:

 OPFPush.getHelper().register();
 //Start registration.
 
}
 
}

You'll get the registration id into EventListener.onRegistered() callback. After registration you'll start receiving push messages into EventListener.onMessage() callback.

Sample

Take a look at the usage of the OPFPush library in our sample application.

##More Information

Simple interation of Google Cloud Messaging

If you want to start using GCM in your application but don't know how. See the easiest way to implement GCM using OPFPush library.

Using of OPFPushReceiver

You can use BroadcastReceiver instead of EventListener for receiving push events. See the following section

Using of JAR dependencies instead of AARs

You also can use JAR dependencies. See the following section.

Notification payload support

GCM Notification payload support was added to the library. Also we have implemented a similar mechanism for all supported push providers. See the following section

Create Custom Push Provider

To create a custom push provider see the following section.

Comparison of most popular push services

Criteria GCM ADM Nokia Notifications OPFPush
Receive messages + + + +
Multiple senders + - + +
Notification payload support + - - +
Asynchronous registration and unregistration - + + +
Retry register on fail - + + +
Retry register on fail after reboot - - - +
Retry unregister on fail - - - +
Check is registration valid on boot - - - +
Retry register after updating app version - - - +
Retry register after changing ANDROID_ID - - - +

License

Copyright 2012-2015 One Platform Foundation  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. 

Resources

Simple Meter for Android.

An easy way to let your titlebar or bottom navigation hiding on scroll for Android.

Limit Indicator (as the name describes) indicates the limit of something being used. For example out of 20 gallons gas, one used 10 gallons of it. Or Your total value was 100 and you have used 80. To show the progress of such usage, I have created the limit indicator which is round and it shows an animation of certain usage. It can also be seen as a Circular Progress Bar.

This repo enables you to show videos instead of usual profile picture for chat heads. Inspired from Facebook's Video profile picture, I decided to replicate its implementation to show videos in profile picture and to create chat heads for the same.

A multi-functional FAB component with customizable options.

BlurKit is an extraordinarily easy to use utility to get live blurring just like on iOS.

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