Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Create custom push provider

Roman Savin edited this page Apr 10, 2015 · 1 revision

To create custom Push Provider you must create class that implement PushProvider interface. Common functionality contains in BasePushProvider class, and we recommend subclass this class.

All providers have Host Application. Host application is an application that contains an implementation of a push provider. Usually this is a store application, like Google Play Store for Google Cloud Messaging.

Requirements for custom Push Provider:

  1. register() and unregister() methods must execute asynchronous operations.
  2. getAvailabilityResult() method must check if the provider can be used on the current device.
  3. isRegistered() method must return true if provider is registered and false otherwise.
  4. getRegistrationId() method must return not null string only when it registered. In all other cases this method must return null.
  5. getName() method must return unique not null string that identify the provider.
  6. getHostAppPackage() method must return not null string with the package of the provider host application.
  7. checkManifest() method must check that all needed permissions, data and components described in manifests.
  8. When onRegistrationInvalid() or onUnavailable method called you must reset all data about registration.

Provider notify OPFPushHelper about registration, or unregistration, or other events by call methods in ReceivedMessageHandler class, such onRegistered() or onMessage(). You can get ReceivedMessageHandler object with call OPFPush.getHelper().getReceivedMessageHandler().

For notify about successful registration or unregistration result you must call ReceivedMessageHandler.onRegistered() or ReceivedMessageHandler.onUnregistered().

For notify about error of registration or unregistration you must call ReceivedMessageHandler.onRegistrationError() or ReceivedMessageHandler.onUnregistrationError(). If you don't know what operation caused an error you must call ReceivedMessageHandler.onError(). OPFPushHelper chooses right callback method relying on current state in this case.

For notify about receive new message call ReceivedMessageHandler.onMessage().

Some provider can notify about deleted messages with call ReceivedMessageHandler.onDeletedMessages(). Not all providers that can notify about this event can provide delete messages count. For unknown count pass value OPFConstants.MESSAGES_COUNT_UNKNOWN as argument messagesCount.