Android Native SDK

Comprehensive reference of iZooto's SDK methods for Android.

📘

Just starting with Android?

Check out our Android Native SDK Integration guide.

Parameter

Data Type

Description

Initialisation

init

Builder Method

Initialises iZooto to register the device for push notifications. Should be called in the onCreate method of your Application class. See Native SDK Setup for details and code examples.

setTokenReceivedListener

Builder Method

Includes the onTokenReceived method to get the subscription token for the current device.

setNotificationReceiveListener

Builder Method

Includes the onNotificationReceived and onNotificationOpened methods to send and receive data when notification is received or clicked.

setLandingURLListener

Builder Method

Includes the onWebView method to open Landing URL inside your app's activity

inAppNotificationBehaviour

Builder Method

Setting to control how iZooto notifications will be shown when one is received while your app is in focus.

unsubscribeWhenNotificationsAreDisabled

Builder Method

If notifications are disabled for your app unsubscribe them from iZooto.

User Permission

setSubscription

Method

Disables iZooto from sending notifications to the current device.

setInAppNotificationBehaviour

Method

Allows end-users to change how notification is displayed when the app is in focus.

Appearance

setIcon

Method

Customize your notification's badge to reflect your brand logo.

Sound

setNotificationSound

Method

Customize the sound that gets played whenever a notification is received on the device.

Analytics

setFirebaseAnalytics

Method

Send events to Google Analytics to track your campaign performance.

Android Tags

addTag

Method

Use this method to tag a users to a specific value.

removeTag

Method

User this method to remove already tagged users from a value.

Get Tags List
REST: GET API

API

Get a list of all the tags that you have created for you app along with the number of users inside that tag.

Send Campaigns to Tagged Users
REST: POST API

API

Use this to send out notifications to only your tagged users.



Initialization

init

Initialises iZooto to register the device for push notifications. Should be called in the onCreate method of your Application class. See Native SDK Setup for details and code examples.

iZooto.initialize(this)
  .build();

Overloaded function accepts previously generated token by FCM, Xiaomi or Huawei. When the correct JSON is provided, the SDK doesn't request cloud messaging service for the token. If the JSON is invalid or the token is of incorrect length, the SDK will generate a new token.

Note: Developers need to make sure that the token passed is valid and active, or the device will be unable to receive notifications.

iZooto.initialize(this, String tokenJson)
  .build();

The parameter tokenJson is the JSON that contains tokens by the respective cloud messaging service. The JSON may contain both FCM and Xiaomi tokens for the same device.

{
    "fcmToken":"<FCM TOKEN>",
  "xiaomiToken":"<XIAOMI TOKEN>",
  "huaweiToken":"<HUAWEI TOKEN>"
}

setTokenReceivedListener

This method will return the subscription token of the current device. The token would only be visible when the app has been launched after installation.

Sample code:

iZooto.initialize(this)
  .setTokenReceivedListener(this)
  .build();

@Override
public void onTokenReceived (String token) {
  Log.i("Device Token: ", token + "");
}

setNotificationReceiveListener

The instance contains two methods that will be called either when a notification is received or when a notification is tapped on from the notification shade.
Sets a notification opened and received handler.

Parameter

Type

Description

Method

onNotificationReceived

Called when a notification is received by your Android device.

Method

onNotificationOpened

Called when a notification is tapped on. Used to open any specific activity on notification click.

Sample code:

// INITIALIZATION
iZooto.initialize(this)
  .setNotificationReceiveListener(new ExampleNotificationHandler())
  .build();

// METHOD CALL
class ExampleNotificationHandler implements NotificationHelperListener {
 
  @Override
  // FIRES WHEN A NOTIFICATION IS RECEIVED
  public void onNotificationReceived (Payload payload) {
    Log.i("iZootoExample", "payload = " + payload.getTitle());
  }
  
  /*
  1. If we clicked notification, then it will show actionType 0.
  2. If we clicked button 1, then it will show actionType 1.
  3. If we clicked button 2, then it will show actionType 2. */
  
  // FIRES WHEN A NOTIFICATION IS CLICKED
  public void onNotificationOpened (String data) {
    String actionType;
    try {
      JSONObject jsonObj = new JSONObject(data);
      actionType = jsonObj.String("actionType");
      
      if (actionType.equalsIgnoreCase("0")) {
        Intent intent =new Intent(getApplicationContext(), YOURACTIVITY.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
      } else if (actionType.equalsIgnoreCase("1")) {
        Intent intent =new Intent(getApplicationContext(), YOURACTIVITY.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
      } else if (actionType.equalsIgnoreCase("2")) {
        Intent intent =new Intent(getApplicationContext(), YOURACTIVITY.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
      }
    } catch (JSONException e) {
        e.printStackTrace();
    }
  }
}
// INITIALIZATION
iZooto.initialize(this)
  .setNotificationReceiveListener(ExampleNotificationHandler())
  .build()

companion object {
  lateinit var instance: MyApplication
    private set
  }

// METHOD CALL
internal class ExampleNotificationHandler : NotificationHelperListener {
  
  // FIRES WHEN A NOTIFICATION IS RECEIVED
  override fun onNotificationReceived(payload: Payload) {
    Log.i("iZootoExample", "payload = " + payload.title)
  }
  
  /*
  1. If we clicked on notification then, it will show actionType 0.
  2. If we clicked on button 1 then, it will show action type 1.
  3. If we clicked on button 2 then, it will show action type 2.*/
  
  // FIRES WHEN NOTIFICATION IS CLICKED
  override fun onNotificationOpened(data: String) {
    var actionType: String? = null
    try {
      val jsonObj = JSONObject(data)
      actionType = jsonObj.getString("actionType")

      if (actionType.equals("0")) {
        val intent = Intent(instance, YOURACTIVITY::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        instance.startActivity(intent)
      } else if (actionType.equals("1")) {
        val intent = Intent(instance, YOURACTIVITY::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        instance.startActivity(intent)
      } else if (actionType.equals("2")) {
        val intent = Intent(instance, YOURACTIVITY::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        instance.startActivity(intent)
      }
    } catch (e: JSONException) {
      Log.e("TAG", "notificationOpened: " + e);
      e.printStackTrace();
    }
  }
}

setLandingURLListener

This method can be used to override iZooto's Landing URL and directly open them inside your app's WebView. No explicit notification handler code is required and you would not have to define additional key: value pairs to do so.
Using this will significantly reduce the campaign creation time.

Sample code:

// INITIALIZATION
iZooto.initialize(this)
  .setLandingURLListener (new ExampleNotificationWebViewHandler())
  .build();

// METHOD CALL
class ExampleNotificationWebViewHandler implements NotificationWebViewListener {
  
  // TO OPEN LANDING URL INSIDE YOUR ACTIVITY
  
  @Override
  public void onWebView (String landingUrl) {
    
    if (landingUrl!=null) {
      Intent intent =new Intent(getApplicationContext(), YOURACTIVITY.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.putExtra("openURL", landingUrl);
      startActivity(intent);
    }
  }
}
// INITIALIZATION
iZooto.initialize(this)
  .setLandingURLListener (new ExampleNotificationWebViewHandler())
  .build()

//METHOD CALL
internal class ExampleNotificationWebViewHandler : NotificationWebViewListener {
  /*To open landing url inside your activity*/
  override fun onWebView(landingUrl: String) {
    if (landingUrl != null) {
      val intent = Intent(instance, YOURACTIVITY::class.java)
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
      intent.putExtra("landingUrl", landingUrl)
      instance.startActivity(intent)
    }
  }
}

inAppNotificationBehaviour

Builder Method

Setting to control how iZooto's notification will be shown when one is received while your app is in focus.

Recommendation: Set to None or Notification when releasing to production.

Parameter

Details

InAppAlert

Default: Native alert dialog display (Note: this is not an In-App Message).

Notification

Native notification display while user has the app in focus

None

Notification will not be displayed while the app is in focus.

iZooto.initialize(this)
  .inAppNotificationBehaviour(iZooto.OSInAppDisplayOption.Notification)
  .build();
iZooto.initialize(this)
  .inAppNotificationBehaviour(iZooto.OSInAppDisplayOption.Notification)
  .build()

Use setInAppNotificationBehaviour to allow end-users to toggle between these behaviours from your app's UI.


unsubscribeWhenNotificationsAreDisabled

Builder Method

Android Devices can still get Data/Silent Notifications even if the user unsubscribes from the App Settings. This will happen when your users go to Settings > Apps and turn off notifications or if they long-press one of your notifications and select "block notifications".

If notifications are disabled for your app, setting this method to true will unsubscribe the user from iZooto and re-subscribe them if they turn notifications back on.

This is false by default, so Android users will be marked as subscribed in this case and can receive data/silent notifications. They will not see any data or get alerted if they unsubscribed from the App Settings.

Parameter

Type

Description

prompt

Boolean

false (Default) - don't unsubscribe users

true - unsubscribe users when notifications are disabled

iZooto.initialize(this)
  .unsubscribeWhenNotificationsAreDisabled(true)
  .build();
iZooto.initialize(this)
  .unsubscribeWhenNotificationsAreDisabled(true)
  .build()


User Permission

setSubscription

Method

Can be used to not deliver notifications to a specific device. This method does not officially subscribe or unsubscribe users from the app settings, it unsubscribes them from receiving a push from iZooto.
You can call this method with false to opt-out users from receiving notifications through iZooto. You can pass true later to opt users back into notifications.

iZooto.setSubscription(true);
iZooto.setSubscription(true)

setInAppNotificationBehaviour

Method

This provides the end-users an ability to choose how the notification will be displayed when your app is in focus. Different values can be called on theonClick() method for any button/toggle.

Values: These can either be None, Notification or InAppAlert.
Refer to inAppNotificationBehaviour for details.

iZooto.setInAppNotificationBehaviour(iZooto.OSInAppDisplayOption.InAppAlert);

❗️

Please make sure that the application class is defined in your AndroidManifest.XML file.



Appearance

setIcon

Method

Used to set a default badge icon for your notification. Badge is a small icon displayed to the left of your application name inside the notification. By default it is a bell icon, that can be overridden to use your App Icon or Brand Logo.

Inside Application Class:

iZooto.setIcon(R.drawable.Image_Name);

🚧

The image should already be present in your drawable folder.

If you prefer to create your own icons, you must make your icons the following size:

Type

Size (px)

Badge Icon (mdpi)

24x24

Badge Icon (hdpi)

36x36

Badge Icon (xhdpi)

48x48

Badge Icon (xxhdpi)

72x72

Badge Icon (xxxhdpi)

96x96



Sound

setNotificationSound

Method

Used to set a custom sound to the notifications when delivered on the device. The device's usual notification sound is played by default, which can be overridden to use a custom sound for your app.

Inside Application Class:

iZooto.setNotificationSound("Sound_File_Name");

🚧

Points to Note

  • The notifications sound file should already be present in the res/raw folder of the project.
  • Supported file types are .mp3 and .wav.
  • The file name needs to be passed without the file extension.


Analytics

setFirebaseAnalytics

Method

iZooto will automatically send notification events to your analytics dashboard if Google Analytics for Firebase is correctly implemented.

Events
The iZooto SDK tracks events that pertain to notification open & receive events. The following events are sent:

Event Name

Purpose

push_notification_opened

An iZooto notification was opened

push_notification_received

An iZooto notification was received.

push_notification_influence_open

An application was opened within 2 minutes of an iZooto notification being received.

The iZooto SDK also sends parameters that contain more info about the particular notification the event is attributed to. These can be directly defined when you create a campaign.

Parameter Name

Purpose

source

To attribute this event's source to the iZooto SDK

medium

A formal indication that the medium for the event is a notification.

campaign

By default, it would be your campaign name.

term

Can be used to track keywords

content

Can be used to differentiate between links that point to the same URL.

Follow the Firebase integration documentation and verify that Firebase is correctly functioning inside your application.

Once everything is set up, use the following method to enable passing events to Firebase.

iZooto.setFirebaseAnalytics(true);
iZooto.setFirebaseAnalytics(true)

👍

You're Done!

Google Analytics for Firebase is now set up to receive iZooto events.


What’s Next

See other integrations you can set up with iZooto

Did this page help you?