-
Notifications
You must be signed in to change notification settings - Fork 17
Create custom push provider
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:
-
register()
andunregister()
methods must execute asynchronous operations. -
getAvailabilityResult()
method must check if the provider can be used on the current device. -
isRegistered()
method must return true if provider is registered and false otherwise. -
getRegistrationId()
method must return not null string only when it registered. In all other cases this method must returnnull
. -
getName()
method must return unique not null string that identify the provider. -
getHostAppPackage()
method must return not null string with the package of the provider host application. -
checkManifest()
method must check that all needed permissions, data and components described in manifests. - When
onRegistrationInvalid()
oronUnavailable
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
.