logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Set custom push rules

If a user is logged in on multiple platforms, the user can configure custom push rules to specify the platforms that can or cannot receive offline push notifications.

Prerequisites

Before you implement the custom push rule feature, make sure that the following conditions are met:

Procedure

Notification for offline push rule update

To receive the notification for custom rule update, register the ZIMEventHandler delegate callback and listen for onUserRuleUpdated.

Untitled
// Listen for custom rules.
@Override
public void onUserRuleUpdated(ZIM zim, ZIMUserRule rule) {
    // Offline push rules.
    userRule.offlinePushRule;
}
1
Copied!

Set offline push rules

To support custom push rules, build the ZIMUserOfflinePushRule class to specify the platforms that do not receive offline push notifications(onlinePlatforms)when the user is online on specified platforms(notToReceiveOfflinePushPlatforms).

To set the above rules, call the updateUserOfflinePushRule method.

Untitled
// Set offline push rules

// Build ZIMUserOfflinePushRule
ArrayList<Integer> onlinePlatforms = new ArrayList<>();

// When the user logs in on win, MacOS, or Linux platforms
ArrayList<Integer> onlinePlatforms = new ArrayList<>();
onlinePlatforms.add(ZIMPlatformType.WIN.value());
onlinePlatforms.add(ZIMPlatformType.MAC_OS.value());
onlinePlatforms.add(ZIMPlatformType.LINUX.value());
offlineRule.setOnlinePlatforms(onlinePlatforms);

// Users do not receive offline push on iPhoneOS, iPadOS, and Android
ArrayList<Integer> notToReceiveOfflinePushPlatforms = new ArrayList<>();
notToReceiveOfflinePushPlatforms.add(ZIMPlatformType.IPHONE_OS.value());
notToReceiveOfflinePushPlatforms.add(ZIMPlatformType.IPAD_OS.value());
notToReceiveOfflinePushPlatforms.add(ZIMPlatformType.ANDROID.value());
offlineRule.setNotToReceiveOfflinePushPlatforms(notToReceiveOfflinePushPlatforms);

// Call the updateUserOfflinePushRule method
ZIM.getInstance().updateUserOfflinePushRule(offlineRule, new ZIMUserOfflinePushRuleUpdatedCallback() {
    @Override
    public void onUserOfflinePushRuleUpdated(ZIMUserOfflinePushRule updatedOfflinePushRule, ZIMError errorInfo) {
    }
});
1
Copied!

Query custom push rules

Call the querySelfUserInfo method to obtain custom offline push rules from theselfUserInfo.userRule.offlinePushRule field in the callback.

Untitled
ZIM.getInstance().querySelfUserInfo(new ZIMSelfUserInfoQueriedCallback() {
    @Override
    public void onSelfUserInfoQueried(ZIMSelfUserInfo selfUserInfo, ZIMError errorInfo) {
         selfUserInfo.userRule.offlinePushRule; // Offline push rules specified by the user.
        
    }
});
1
Copied!

Previous

Implement offline push notification

Next

Integrate FCM