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.
From time to time, like every time you starts your application, you should register your application in case the user have uninstalled the previous distributor. If the previous distributor is uninstalled, you can fallback to the default one again.
Therefore, you can use tryUseCurrentOrDefaultDistributor to select the saved distributor or the default one when your application starts (when your main activity is created for instance).
When the distributor is saved, you can call registerApp
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.
If you want, you can use the library org.unifiedpush.android:connector-ui
instead, it displays a dialog explaining why the OS picker is going to ask which application to pick.
import org.unifiedpush.android.connector.UnifiedPush
/* ... */
UnifiedPush.tryUseCurrentOrDefaultDistributor(context) { success ->
if (success) {
// We have a distributor
// Register your app to the distributor
UnifiedPush.registerApp(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.registerApp(
context,
INSTANCE_DEFAULT,
messageForDistributor,
vapid
);
}
});
Be aware that tryUseDefaultDistributor 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
You will probably want to allow the users to use another distributor but their default one.
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 registerApp
.
When the distributor is saved, you can call registerApp
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.
If you want, the library org.unifiedpush.android:connector-ui
offers a customizable dialog that request user's choice and register to this distributor.
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, eg. with a dialog
val userDistrib = yourFunc(distributors)
// save the distributor
UnifiedPush.saveDistributor(context, userDistrib)
// register your app to the distributor
UnifiedPush.registerApp(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.registerApp(
context,
INSTANCE_DEFAULT,
messageForDistributor,
vapid
);
Unsubscribe
To unsubscribe, simply call unregisterApp
. Set the instance you want to unsubscribed to if you used one during registration.
It removes the distributor if this is the last instance to unregister.
Functions
Get the distributor registered by the user, and the distributor has already respond 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 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.