Listening for Callbacks

The PushIO SDK provides callbacks for certain important events. These are optional listeners that can be registered through PushIOManager and implemented for additional information about an event.

This topic describes the available listeners

PushIOListener

Provides the following callbacks for registration events:

void onPushIOSuccess();

void onPushIOError( String message );

PushIOEngagementListener

Provides the following callbacks for events related to engagements:

void onEngagementSuccess();

void onEngagementError( String error );

PushIONotificationServiceDiscoveryListener

Provides the following callbacks for notification service (that is, GCM/ADM) availability status:

void onNotificationServiceAvailable( String notificationServiceType );

void onNotificationServicesUnavailable( Bundle reasonExtras );
  • onNotificationServicesUnavailable() also notifies the listener if the Google Play services framework on the user's device is outdated.

  • The reasonExtras parameter contains the notification service name (for example, GCM) and its error code.

You can pass this error code to the Google Play services library to take the appropriate action (for example, prompt the user to update Google Play services framework on their device), as shown in the example below:

                    @Override
                    public void onNotificationServicesUnavailable( Bundle reasonExtras ) {
                        Log.w(TAG, "No notification services detected.");
                        if (reasonExtras.containsKey(PushIONotificationServiceType.GCM)) {
                            final int gcmErrorCode = reasonExtras.getInt(PushIONotificationServiceType.GCM);

                            if( GooglePlayServicesUtil.isUserRecoverableError(gcmErrorCode)){
                                GooglePlayServicesUtil.showErrorDialogFragment(gcmErrorCode, this, 1, new DialogInterface.OnCancelListener() {
                                    @Override
                                    public void onCancel(DialogInterface dialog) {
                                        // User cancelled dialog.
                                    }
                                });
                            }
                        }
                    }
                

                        override fun onNotificationServicesUnavailable(reasonExtras: Bundle?) {
                        Log.w("TAG", "No notification services detected.")
                        if (reasonExtras != null && reasonExtras.containsKey(PushIONotificationServiceType.GCM)) {
                            val gcmErrorCode: Int = reasonExtras.getInt(PushIONotificationServiceType.GCM)
                            if (GooglePlayServicesUtil.isUserRecoverableError(gcmErrorCode)) {
                                GooglePlayServicesUtil.showErrorDialogFragment(gcmErrorCode, this, 1) {
                                    // User cancelled dialog.
                                }
                            }
                        }
                    }          

You can register for these callbacks via the PushIOManager class instance.

                    PushIOManager pushIOManager = PushIOManager.getInstance(this);
                    pushIOManager.registerPushIOListener(this);
                    .
                    .
                    pushIOManager.registerApp();
                
                    val pushIOManager = PushIOManager.getInstance(applicationContext)
                    pushIOManager.registerPushIOListener(this)
                    .
                    .
                    pushIOManager.registerApp()
                    

IMPORTANT: Only call registerApp() after you have registered for the desired events.