Zoho Desk | Mobile SDK - Android
Introduction

Introduction

The Zoho Desk Software Development Kit (SDK) for Android is aimed at helping you build a custom app containing the features and functionalities of Zoho Desk. When you build an app using this SDK, you get to choose which help desk module you want to retain and which one you want to exclude. Besides, you can design the app UI according to your requirements and style guidelines, while powering the back-end of the app using the SDK.

Getting Started

There are a few requirements that must be met before you can start creating an app using the Zoho Desk SDK for Android. These requirements are as follows.


Zoho Account

Having a Zoho account is an absolute must to be able to use the Zoho Desk SDK for Android. If you do not have an account yet, sign up for one by visiting this link.


Client ID and Secret

Next, you require the client ID and secret for your app. To receive these credentials, you must first register your app by performing the following steps.

  1. Visit Zoho's Developer Console. Developer Console.
  2. API Credentials page, click the Add Client ID button.
    The Create Zoho Client ID form appears.
  3. In this form, enter the following details:
    • Client Name: Name of your app
    • Client Domain: Website of your app
    • Authorized redirect URIs: Redirect URI for authentication
  4. In the Client Type drop-down list, choose Mobile.
  5. Click the Create button.
    The Client ID and Client Secret are displayed.

Build Configuration - Versions Required

compileSdkVersion - 27
buildToolsVersion - 27.0.3
supportLibVersion - 27.1.1
minSdkVersion - 16
targetSdkVersion - 27

Building Your App

As the first step towards building your app using this SDK, add the code snippets on the right panel to the build.gradle file of your app.

compile 'zohoaccounts_android_external_lib.milestones:dev:ZOHOACCOUNTS_ANDROID_EXTERNAL_LIB_V2_6_BETA2'

To enable IAM login flow





compile com.zoho.desksdk:1.0

To add the Zoho Desk SDK to your Android app, include the desksdk library.



compile 'com.zoho.deskui:1.0'

To include Zoho Desk UI components too in your app, add the deskui library.



classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21"

Since the ZohoDeskSDK library was built using Kotlin, you must also add the Kotlin gradle plugin.

Authenticating Users

To enable user authentication, perform the following steps.

String SCOPES = "aaaserver.profile.READ," + "ZohoSupport.tickets.ALL," + "ZohoSupport.basic.READ," + "ZohoSupport.basic.CREATE," + "ZohoSupport.settings.READ," + "ZohoSupport.settings.CREATE," + "ZohoSupport.settings.UPDATE," + "ZohoSupport.settings.DELETE," + "ZohoSupport.contacts.READ," + "Zohosearch.securesearch.READ," + "zohocontacts.userphoto.READ," + "ZohoSupport.feeds.ALL";

1. Add the various scopes to be supported.
















ZohoSDK.getInstance(this).init(scopes, true) where init param 1 - Scopes mentioned above, param 2 - toShow Log or not

2. In the onCreate method in the Application class, include the code snippet on the right panel.








Strings: <string name="c_id"> YOUR CLIENT ID </string> <string name="c_secret"> YOUR CLIENT SECRET ID </string> <string name="redirect_url">schemeName://</string> <string name="accounts_url">https://accounts.zoho.com</string> <string name="enable.logs">true</string> <string name="is.debug">true</string>

3. In the strings.xml file in the project directory of your app, include the strings on the right panel.










Activity: <activity android:name=".RedirectActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="schemeName" /> </intent-filter> </activity>

4. Create a subclass called RedirectActivity from the Activity() class, and add it to the AndroidManifest.xml file in the project directory.










his redirection activity is called if user login is successful.

ZohoSDK.getInstance(this).handleRedirection(this)

Then, in the onCreate() method in RedirectActivity, add this single line.



ZohoSDK sdk = ZohoSDK.getInstance(getApplicationContext()); if(sdk.isUserSignedIn()){ sdk.presentLoginScreen(this, new ZohoTokenCallback() { @Override public void onTokenFetchInitiated() { } @Override public void onTokenFetchComplete(ZohoToken zohoToken) { } @Override public void onTokenFetchFailed(ZohoErrorCodes zohoErrorCodes) { } },null); } else{ // start intent to your first activity }

Finally, in the first activity of your app, include the code on the right panel.



























Handling User Logout

sdk.revoke(new ZohoSDK.OnLogoutListener() { @Override public void onLogoutSuccess() { } @Override public void onLogoutFailed() { } });

To log users out from the SDK, use the code snippet on the right panel.












ZohoDeskUIKitKt.flushUserData(context);

Also, make sure to clear user data when a user logs out. To perform this activity, use the code snippet on the right panel.


Note: Clearing of user data is possible only in the Zoho Desk UI Kit.

Integrating Your App with the Zoho Desk SDK

ZDeskSdk.getInstance().init(this,this,ZDDOMAIN.US) where, param 1 - callback param 2 - context param 3 - Domain

To integrate the Zoho Desk SDK with your app, add the code snippet on the right panel to the onCreate method in the application class.







Similarly, implement ZDAuthenticationInterface in the Application class.

@Override public void getAuthToken(final @NotNull ZDSdkInterface callback) { ZohoSDK.getInstance(this).getToken(new ZohoTokenCallback() { @Override public void onTokenFetchInitiated() { } @Override public void onTokenFetchComplete(ZohoToken zohoToken) { callback.setOAuthToken(zohoToken.getToken()); /* On success of the Token Fetch this method will get called */ } @Override public void onTokenFetchFailed(ZohoErrorCodes zohoErrorCodes) { /* On Failure of the Token Fetch this method will get called */ callback.onOAuthTokenFetchFailed(zohoErrorCodes.getDescription(), /* Error Code*/); } }) }

The getAuthToken method handles authentication related to API calls for the Zoho Desk SDK for Android. This method fetches the OAuthToken that the SDK requires for making API calls. Configure the method as shown in the right panel.


















Zoho Desk APIs

Below are a few examples of the APIs provided by Zoho Desk.


Get organization

ZDOrganizationAPIHandler.INSTANCE.getOrganisation(new ZDCallback() { @Override public void onFailure(@org.jetbrains.annotations.Nullable Call call, @NotNull ZDBaseException exception) { // ToDo on Failure call } @Override public void onSuccess(@NotNull ZDResult result) { // ToDo on Success call } },mOrgId);

This API returns details of an organization from the help desk portal.













Get ticket

ZDTicketAPIHandler.INSTANCE.getTicketDetail(new ZDCallback() { @Override public void onFailure(@org.jetbrains.annotations.Nullable Call call, @NotNull ZDBaseException exception) { // ToDo on Failure call } @Override public void onSuccess(@NotNull ZDResult result) { // ToDo on Success call } },mOrgId,mTicketId,optionalParams);

This API fetches a ticket from the help desk portal.















Help desk modules are referred to in the ZD<Module Name>APIHandler format in API requests and ZD<Module Name> format in API responses.

To download a sample app to check how the APIs work, click here.

To view the complete list of Zoho Desk APIs, click here.

Zoho Desk UI Kit for Android

The Zoho Desk UI Kit for Android is a plug-and-play feature that helps build an app using standard UI elements created by Zoho. All that you need to do is add a view to the app and call an init method with the params required.

Currently, the UI kit supports the Ticket List and Ticket Detail components.

Ticket List Component

ZDTicketListView mTicketListView = findViewById(R.id.ticketList); mTicketListView.initTicketList(this, mOrgId, mDepartmentId, mConfig, new ZDTypeCallBack () { @Override public void onFailed(ZDErrorData error) { /* ZDErrorData will contain error message and error code */ } @Override public void onSuccess(ZDNetworkState data) { /* This method will be called on every load more calls data.getMsg() above method contains message as ZD_INITIAL_LOADING or ZD_LOADING */ if (data.getMsg().equals(ZD_INITIAL_LOADING)) { loader.setVisibility(View.GONE); } } }, new ZDClickListener () { @Override public void onClick(ZDTicketsMetaResponse data, @NotNull View view) { /* ToDo this callback will provide you with clicked item response object and and its view*/ } });

To display the ticket list in your app, add the ZDTicketListView component to the layouts XML file of your app and initialize the view as specified in the right panel.































ZDTicketListconfig mConfig= new ZDTicketListConfig.ZDBuilder(). setAssignee("Unassigned").setChannels("Email").// No I18N setPageSize(99). setStatus("open"). setReceivedInDays(15). sortBy("dueDate"). orderBy("-"). build();

You can customize the ticket list by altering the different attributes in the ZDTicketListConfig builder object. The code snippet on the right panel shows a sample customization.











To view the complete list of attributes supported, click here.

Ticket Detail Component

ZDTicketDetailFragment.initView(648638721, mTicketId, mconfig);

To display the ticket detail view in your app, add the ZDTicketDetailFragment component in the layouts XML file of your app. Then, initialize the view as specified in the right panel.


ZDTicketDetailConfig mconfig =new ZDTicketDetailConfig.ZDBuilder().setConversationPageSize(40).build();

The ticket detail view displays ticket information, based on the configuration set in the ZDTicketDetailConfig builder object. The code for a sample configuration is displayed on the right panel.