UnifiedPush
Object containing functions to interact with the distributor
Use user's default distributor
Users are allowed to define a default distributor on their system, because UnifiedPush distributors have to be able to process a deeplink.
When you set UnifiedPush for the first time on your application, you will want to use the default user's distributor.
Therefore, you can use tryUseCurrentOrDefaultDistributor to select the saved distributor or the default one when the user enables UnifiedPush.
When the distributor is saved, you can call register to request a new registration. It has optional parameters, the following example uses messageForDistributor and vapid. You can use instance to bring multiple-registration support to your application.
import org.unifiedpush.android.connector.UnifiedPush
/* ... */
UnifiedPush.tryUseCurrentOrDefaultDistributor(context) { success ->
if (success) {
// We have a distributor
// Register your app to the distributor
UnifiedPush.register(context, messageForDistributor, vapid)
}
}import static org.unifiedpush.android.connector.ConstantsKt.INSTANCE_DEFAULT;
import org.unifiedpush.android.connector.UnifiedPush;
/* ... */
UnifiedPush.tryUseCurrentOrDefaultDistributor(context, success ->{
if (success) {
// We have a distributor
// Register your app to the distributor
UnifiedPush.register(
context,
INSTANCE_DEFAULT,
messageForDistributor,
vapid
);
}
});Be aware that tryUseCurrentOrDefaultDistributor starts a new translucent activity in order to get the result of the distributor activity. You may prefer to use LinkActivityHelper directly in your own activity instead.
Use another distributor
The user may want to use another distributor: it can be achieved with tryPickDistributor.
Implement your own distributor picker
For this, you can get the list of available distributors with getDistributors.
Once the user has chosen the distributor, you have to save it with saveDistributor. This function must be called before register.
When the distributor is saved, you can call register to request a new registration. It has optional parameters, the following example uses messageForDistributor and vapid. You can use instance to bring multiple-registration support to your application.
import org.unifiedpush.android.connector.UnifiedPush
/* ... */
// Get a list of distributors that are available
val distributors = UnifiedPush.getDistributors(context)
// select one or ask the user which distributor to use, e.g. with a dialog
val userDistrib = yourFunc(distributors)
// save the distributor
UnifiedPush.saveDistributor(context, userDistrib)
// register your app to the distributor
UnifiedPush.register(context, messageForDistributor, vapid)import static org.unifiedpush.android.connector.ConstantsKt.INSTANCE_DEFAULT;
import org.unifiedpush.android.connector.UnifiedPush;
/* ... */
// Get a list of distributors that are available
List<String> distributors = UnifiedPush.getDistributors(context);
// select one or show a dialog or whatever
String userDistrib = yourFunc(distributors);
// the below line will crash the app if no distributors are available
UnifiedPush.saveDistributor(context, userDistrib);
UnifiedPush.register(
context,
INSTANCE_DEFAULT,
messageForDistributor,
vapid
);Unsubscribe
To unsubscribe, simply call unregister. Set the instance you want to unsubscribe to if you used one during registration.
It removes the distributor if this is the last instance to unregister.
Regular re-registration
To ensure the distributor is still installed, and the application is correctly registered, it is recommended to regularly re-register to the distributor.
For this, from time to time, like every time the application starts, you can control if the distributor is still installed with getAckDistributor, then call register.
If the previous distributor is uninstalled, you can inform the user and/or fallback to the default one again, with tryUseCurrentOrDefaultDistributor.
Functions
Get the distributor registered by the user, and the distributor has already responded to our requests
Get a list of available distributors installed on the system
Get the distributor registered by the user, but the distributor may not have respond yet to our requests. Most of the time getAckDistributor is preferred.
Request a new registration for the instance to the saved distributor.
register with additional KeyManager parameter.
Unregister all instances and remove the distributor
removeDistributor with additional KeyManager parameter.
Save distributor as the new distributor to use
Try to pick a distributor opening the deeplink "unifiedpush://link", ignoring the default one
Try to use the saved distributor else, use the default distributor opening the deeplink "unifiedpush://link"
Try to use the distributor opening the deeplink "unifiedpush://link"
Send an unregistration request for the instance to the saved distributor and remove the registration. Remove the distributor if this is the last instance registered.
unregister with additional KeyManager parameter.