Android Native SDK

Comprehensive reference of iZooto's SDK methods for Android apps built with the Native framework.

📘

Just starting with Android?

Check out our Android Native SDK Integration guide.

ParameterData TypeDescription
Initialisation
initBuilder MethodInitialises 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.
setTokenReceivedListenerBuilder MethodIncludes the onTokenReceived method to get the subscription token for the current device.
setNotificationReceiveListenerBuilder MethodIncludes the onNotificationReceived and onNotificationOpened methods to send and receive data when notification is received or clicked.
setLandingURLListenerBuilder MethodIncludes the onWebView method to open Landing URL inside your app's activity.
unsubscribeWhenNotificationsAreDisabledBuilder MethodIf notifications are disabled for your app, unsubscribe them from iZooto.
Notification Channel
setNotificationChannelNameMethodCan be used to set a custom channel name for the notifications.
User Permission
setSubscriptionMethodDisables iZooto from sending notifications to the current device.
navigateToSettingsMethodCan be used to re-direct the users to the App Settings page to check the notification permissions, etc.
Sound
setNotificationSoundMethodCustomize the sound that gets played whenever a notification is received on the device.
Analytics
setFirebaseAnalyticsMethodSend events to Google Analytics to track your campaign performance.
Android Tags
addTagMethodUse this method to tag a user to a specific value.
removeTagMethodUse this method to remove already tagged users from a value.
Pulse
enablePulseMethodUse this method to show a personalised news feed to your app users.
Get Tags List
REST: GET API
APIGet a list of all the tags that you have created for your app along with the number of users inside that tag.
Send Campaigns to Tagged Users
REST: POST API
APIUse 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 notification opened and received handler.

ParameterTypeDescription
MethodonNotificationReceivedCalled when a notification is received by your Android device.
MethodonNotificationOpenedCalled 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)
    }
  }
}

unsubscribeWhenNotificationsAreDisabled

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 unsubscribe from the App Settings.

ParameterTypeDescription
promptBooleanfalse (Default) - don't unsubscribe users

true - unsubscribe users when notifications are disabled
iZooto.initialize(this)
  .unsubscribeWhenNotificationsAreDisabled(true)
  .build();
iZooto.initialize(this)
  .unsubscribeWhenNotificationsAreDisabled(true)
  .build()

Notification Channel

setNotificationChannelName

This method can be used to define a custom Notification Channel name for the push notifications.

setNotificationChannelName(String channelName);

🚧

Points to Note

  • The Notification Channel name cannot be more than 30 characters and the name cannot contain special characters.
  • If no channel name is provided or if the character length is more than 30 characters, then the channel name will be AppName Notifications.
  • If the App Name is also not available, then the channel name will be Push Notifications.

User Permission

setSubscription

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)

❗️

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

navigateToSettings

This method can be used to take the users to the App Settings page to check the notification permissions and/or other app settings. This method becomes useful if the user has disabled notifications and you would like to have an option inside the app itself to re-direct the user to the App Settings page to allow the user to re-enable the notification permissions. The method can be called at the click of a button or any other event as per requirement.

navigateToSettings(Activity activity)

Sound

setNotificationSound

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

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 NamePurpose
push_notification_openedAn iZooto notification was opened
push_notification_receivedAn iZooto notification was received.
push_notification_influence_openAn 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 NamePurpose
sourceTo attribute this event's source to the iZooto SDK
mediumA formal indication that the medium for the event is a notification.
campaignBy default, it would be your campaign name.
termCan be used to track keywords
contentCan 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.

Pulse

enablePulse

Pulse is a personalized news feed that can be embedded within the app.

Below is the list of relevant parameters.

Parameter NamePurpose
contextPass the current object
isBackIntenttrue / false. True will trigger Pulse on Back button

Syntax

iZooto.enablePulse(<currentObject>,<isBackIntent>);

Example

iZooto.enablePulse(MainActivity.this,false);

What’s Next

See other integrations you can set up with iZooto