Install the Android UI library for the user app
The Android UI library helps you use the UI components of the modules and also to design your own custom UIs.
1. Prerequisites
- The latest version of Android Studio
2. Register your Android app with Zoho
- Edit your Zoho Creator application.
- Navigate to its Settings page.
- Click Mobile SDK under Developer Tools.
- Under the For Users section, click For Android. A pane will slide in from the right.
- Select the UI & Core library.
- Click the Generate Client Credentials. This will generate the client ID and client secret for the Android app that you want to integrate with your Creator application.
- Downloaded the zcapp_info.properties file, then add it to your project's raw folder: "<your_project_folder>/app/src/main/res/raw". (Create a folder named raw in this location if it doesn't exist)
3. Install the Android UI library for the user app
- Integrate SDK in your Android app:
Add the Zoho maven repository URL in app/build.gradle.
allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://maven.zohodl.com'
}
}
}Note:While adding the repository URLs in build.gradle you may encounter Build was configured to prefer settings repositories over project repositories issue. To proceed further, you need to add the repository URLs in settings.grade.Integrate Zoho Creator UI Library & Authentication Library in app/build.gradle
dependencies {
implementation 'com.zoho.creator:creator-ui:1.5'
implementation 'com.zoho.accounts.android:zaccountssdk:V3_1'
}
- Click Sync Now in the bar that appears in the IDE.
- Configure your project with the following code:
Add the below string in the strings.xml of your app:
<string name="ui.label.appname" translatable="false"> YOUR APP NAME </string>
<string name="c_id"> GENERATED CLIENT ID </string>
<string name="c_secret"> GENERATED CLIENT SECRET ID </string>
<string name="redir_url"> REGISTERED REDIRECT URI</string>
<string name="accounts_url">https://accounts.zoho.com</string><!-- enter the accounts URL of your respective DC. For eg: US users use 'https://accounts.zoho.com'. -->
Your Creator account's base URL depends on the data center it's associated with. Learn moreIn the oncreate method in your application / activity class, Initialize the Accounts SDK as follows:
ZohoSDK.getInstance(this).init(scopes, showlogs)
where,
scopes - "aaaserver.profile.READ,zohocontacts.userphoto.READ,ZohoContacts.contactapi.READ,
ZohoCreator.meta.CREATE,ZohoCreator.meta.READ,ZohoCreator.meta.UPDATE,
ZohoCreator.meta.DELETE,ZohoCreator.data.CREATE,ZohoCreator.data.READ,
ZohoCreator.data.UPDATE,ZohoCreator.data.DELETE,Stratus.stratusop.READ,
ZohoCRM.modules.READ,ZohoCRM.users.READ"Note: The scope list have been updated for version 1.4 and above.- showLogs - To show debug logs or not
Create an Activity called HandleRedirectActivity and add the following code in its oncreate method:
ZohoSDK.getInstance(this).handleRedirection(this);
Add the following code to the AndroidManifest.xml file:
<activity android:name=".HandleRedirectActivity" android:exported="true">
<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="<REDIRECTURI_WITHOUT_COLON_AND_SLASH>" />
</intent-filter>
</activity>To open the login screen, add the below code snippet:
val sdk = ZohoSDK.getInstance(applicationContext) if (!sdk.isUserSignedIn) { sdk.presentLoginScreen(this, object : ZohoTokenCallback { override fun onTokenFetchInitiated() { } override fun onTokenFetchComplete(zohoToken: ZohoToken?) { // This method will be called after user logged-in successfully } override fun onTokenFetchFailed(zohoErrorCodes: ZohoErrorCodes?) { // This method will be called if any error occurred in the login. You will receive the error code in this callback. } }, null) } else { // Start intent to your first activity }
Implement the Creator Authentication interface ZCOauthHelper as follows:
class ZCAuthImpl(private val context: Context) : ZCOauthHelper { @Throws(ZCException::class) override suspend fun getAccessToken(): String? { return ZohoSDK.getInstance(context).token.token } override fun getInitialScopes(context: Context): String { return "" } override fun isUserSignedIn(): Boolean { return false } override fun getUserData(): Any? { return null } override fun getTransformedUrl(url: String): String { return url } override fun checkAndLogout(): Boolean { return false } override fun isEnhanceTokenNeeded(newScopes: String): Boolean { return false } override fun enhanceToken(tokenHelper: ZCOauthHelper.ZCOAuthTokenHelper, newScopes: String) { } }
Add the following code to your application's / activity's oncreate method to set the instance of Authentication interface to the Creator SDK:
ZCAPIUtil.setOAuthHelper(ZCAuthImpl(applicationContext))
Add the following to your AndroidManifest.xml file, under the application tag:
android:name="com.zoho.creator.a.ZCreatorApplication"
FAQ
- I'm getting merge conflicts while generating a build. How to resolve them?
Please add tools:replace="android:allowBackup,android:label,android:theme" under the application tag in the AndroidManifest.xml file and try again. - I get the "Duplicate class android.support.v4.app" error. What should I do?
To resolve this error, you'll need to add android.enableJetifier=true in gradle.properties file. - I get the "Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified" error. What should I do?
To resolve this error, please add implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0' to your dependency list
References
- Sample code snippets
- Familiarize yourself with Mobile SDK for Android by trying out our sample application here.
- Android SDK documentation for detailed information about the various SDK methods.