Documentation

Android SDK Reference


Register devices, receive push notifications, and more with our Android SDK.

Register Devices

Assign a unique token to the device, so you can send push notifications to it:

String deviceToken = Pushy.register(Context ctx);

In case the device has already been registered, this method will simply return the existing token instead.

Note: This method is a synchronous, blocking call, so make sure to only execute it from within a background thread.

Check Registration Status

Determine whether the device has already been registered to receive notifications:

boolean isRegistered = Pushy.isRegistered(Context ctx);
Listen for Notifications

Call this method in your application's main launcher activity to restart the socket service, in case the user force-closed your application:

Pushy.listen(Context ctx);
Manage Topic Subscriptions

Subscribe a registered device to one or more topics:

Pushy.subscribe(String topic, Context ctx);

Unsubscribe a registered device from one or more topics:

Pushy.unsubscribe(String topic, Context ctx);

Note: Make sure to execute this method from a background thread, similar to Pushy.register(Context).

Topic names are case-sensitive and must match the following regular expression: [a-zA-Z0-9-_.]+. You may also pass in a String[] array with multiple topics.

Refer to the Subscribe to Topics documentation page for more information.

Toggle Push Notifications

Enable or disable push notifications for the device after it has been registered:

Pushy.toggleNotifications(Boolean enabled, Context ctx);
Toggle Permission Verification

Enable or disable AndroidManifest permission verification if it emits a false alarm:

Pushy.togglePermissionVerification(Boolean enabled, Context ctx);

Note: Only disable permission verification if the SDK wrongfully detects that one or more SDK permissions are missing from your AndroidManifest.xml.

Configure a Notification Channel

Automatically configure a Notification Channel for your notifications on devices running Android O and up:

Pushy.setNotificationChannel(Notification[Compat].Builder builder, Context context);

Refer to the Setup BroadcastReceiver documentation page for sample usage.

Modify the Socket Heartbeat Interval

Increase or decrease the default 5 minute (300 second) socket keep-alive interval in special situations (please consult with us first):

Pushy.setHeartbeatInterval(int seconds, Context ctx);

Note: The heartbeat interval must be greater than or equal to 60 seconds. In addition, please call this method before Pushy.listen(Context) in your main launcher activity for it to take effect.

Toggle Wi-Fi Sleep Policy Compliance

Enable or disable Wi-Fi sleep policy compliance to prevent the SDK from acquiring a wake lock in case the "Keep Wi-Fi on during sleep" device setting is set to "Never".

Pushy.toggleWifiPolicyCompliance(Boolean enabled, Context ctx);
Configure App ID

By default, the SDK will automatically authenticate using your app's package name.

You can manually pass in your Pushy App ID (Pushy Dashboard -> Click your app -> App Settings -> App ID) to override this behavior:

Pushy.setAppId(String appId, Context ctx);

Note: Please call this method before Pushy.register(Context) for it to take effect.

Reset the Device Token

Invoke this method to clear the device token, in case you would like to reset it. Calling Pushy.register(Context) for this device in the future will generate a new token.

Pushy.unregister(Context ctx);
Listen to SDK Logcat Output

Register a listener that will be invoked every time the SDK writes a new log entry to the Android logcat.

PushyLogger.setLogListener(new PushyLogger.PushyLogListener() {
    @Override
    public void onDebugLog(String message) {
    }

    @Override
    public void onErrorLog(String message) {
    }
});