Coder Social home page Coder Social logo

opfpush's Introduction

OPFPush

Android Arsenal

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.

opfpush's People

Contributors

akarimova avatar antongitname avatar grimreio avatar kirich1409 avatar romanzhilich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opfpush's Issues

server side

Hello ,
Thank you for implementing such great library for pushing notifications. I was wondering if there is a suitable server side PHP class that works fine with your package. I have not found anything yet . I mean what do you use yourself for server side programming of this.
Thanks alot

Nokia server URL won't fetch

Google URL Fetch Service doesn't fetch Nokia URL no matter what.
I tried using java.net classes and low level requests, but sockets are not available anyway and every API uses URL Fetch Service.

Nokia web console, curl or some other tools can be used to send requests for now.

Cannot run a test application

Getting this exception when trying to start a sample app:

java.lang.NoClassDefFoundError: com.amazon.device.messaging.ADM
            at org.onepf.opfpush.adm.ADMDelegate.<init>(ADMDelegate.java:44)
            at org.onepf.opfpush.adm.ADMProvider.<init>(ADMProvider.java:51)
            at org.onepf.opfpush.pushsample.DemoApplication.onCreate(DemoApplication.java:44)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4551)
            at android.app.ActivityThread.access$1500(ActivityThread.java:163)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5335)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)

btw, there are several stores on the phone installed including Google play store and Amazon app store.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.