Android integration
This section describes the process of integrating PLuG using the DevRev SDK with your Android app.
Requirements
- Android Studio 2022.1.1 or later
- Android Gradle plugin version 7.4 or later
- Gradle version 7.6 or later
- Minimum Android SDK 24
Integration
To integrate the latest version of our SDK into your app, follow these steps:
Kotlin
Groovy
-
Add the following dependencies to your app’s
build.gradle.kts
file to get the latest version of our SDK: -
Our SDK is available on Maven Central. To access it, add
mavenCentral
to your rootbuild.gradle.kts
file.
After completing these steps in your build.gradle.kts
Kotlin script, you should be able to import and use the DevRev SDK in your Android application.
Set up the DevRev SDK
- In DevRev, go to Settings > PLuG settings to obtain Your unique App ID (referred to as
supportID
in the code). - After obtaining the credentials, you can configure the DevRev SDK in your app. The SDK will be ready for use once you execute the configuration method.
Kotlin
Java
- To configure the SDK, you need to call the following method inside your
Application
class:
If you don’t have a custom Application
class, create one as shown below.
Kotlin
Java
-
In the
onCreate
method of yourApplication
, configure the DevRev SDK with the required parameters using the credentials obtained earlier. -
Ensure that the custom application is specified in the
AndroidManifest.xml
, as shown below:
Identification
To use certain features of the DevRev SDK, user identification is required. You can select from the following methods to identify users within your application:
The identification function should be placed appropriately in your app after the user logs in. If you have the user information available at app launch, call the function after the DevRev.configure(context, appID)
method.
The Identity
structure allows for custom fields in the user, organization, and account traits. These fields must be configured through the DevRev app before they can be utilized. For more information, refer to Object customization.
Anonymous identification
The anonymous identification method allows you to create an anonymous user with an optional or random user identifier, ensuring that no other data is stored or associated with the user.
Kotlin
Java
Unverified identification
The unverified identification method identifies users with a unique identifier, but it does not verify their identity with the DevRev backend.
Kotlin
Java
The function accepts the Identity
object, where the user identifier (userId
) is the only required property; all other properties are optional.
For example:
Kotlin
Java
Update user information
To update a user’s information, use the following method:
Kotlin
Java
The function accepts the DevRev.Identity
ojbect.
The userID
property cannot be updated.
PLuG support chat
Once user identification is complete, you can start using the chat (conversations) dialog supported by our DevRev SDK. To open the chat dialog, your application should use the showSupport
API, as shown in the following example:
Kotlin
Java
The DevRev SDK also provides a support button, which can be integrated into your application. To include it on the current screen, add the following code to your XML layout:
The support button can be customized using default parameters, enabling you to tailor its appearance to your application’s design.
and
At this stage, your app is fully configured to utilize all functionalities of the DevRev PLuG SDK. Pressing the support button directs the user to the chat interface, enabling effective interaction and support.
Analytics
The DevRev SDK allows you to send custom analytic events by using a name and a string hashmap. You can track these events using the following function:
Kotlin
Java
For example:
Kotlin
Java
Session analytics
The DevRev SDK offers session analytics features to help you understand how users interact with your app.
Opt in or out
End users can opt in or out of the session analytics feature, enabling them to control whether their interactions are tracked for analytics.
Kotlin
Java
This method terminates and deletes the current session recording and also disables future session recording by our SDK for this user.
Kotlin
Java
If session recording was disabled for the user using the stopAllMonitoring()
method, you can enable recording at runtime with this method.
This feature only stores a monitoring permission flag and does not provide any user interface or dialog.
Session recording
You can enable session recording to capture user interactions with your app.
The session recording feature is opt-out and is enabled by default.
Here are the available methods to help you control the session recording feature:
Session properties
You can add custom properties to the session recording to help you understand the context of the session. The properties are defined as a hashmap of string values.
Kotlin
Java
To clear the session properties in scenarios such as user logout or when the session ends, use the following method:
Kotlin
Java
Timers
The DevRev SDK offers a timer mechanism to measure the time spent on specific tasks, allowing you to track events such as response time, loading time, or any other duration-based metrics.
The mechanism utilizes balanced start and stop methods, both of which accept a timer name and an optional hashmap of properties.
To start a timer, use the following method:
Kotlin
Java
To stop a timer, use the following method:
Kotlin
Java
For example:
Kotlin
Java
Screen tracking
The DevRev SDK offers automatic screen tracking to help you understand how users navigate through your app. Although activities are automatically tracked, you can manually track screens or fragments using the following method:
Kotlin
Java
For example:
Kotlin
Java
Push notifications
You can configure your app to receive push notifications from the DevRev SDK. The SDK is designed to handle push notifications and execute actions based on the notification’s content.
DevRev sends push notifications to your app to alert users about new messages in the PLuG support chat.
To receive push notifications, you need to configure your DevRev organization by following the instructions in the push notifications section.
You need to ensure that your Android app is configured to receive push notifications. To set it up, follow the Firebase documentation.
Register for push notifications
Push notifications require SDK configuration and user identification, whether unverified or anonymous, to ensure delivery to the correct user.
The DevRev SDK offers a method to register your device for receiving push notifications. You can register for push notifications using the following method:
Kotlin
Java
The method requires a device identifier that persists across device restarts and app launches. This could be a Firebase installation ID, Android ID, or a unique system identifier. To obtain the device token for Firebase Cloud Messaging, follow these steps:
- Use the
FirebaseMessaging
object. - Call the
firebaseMessaging.token.await()
method.
This method will generate and return the device token.
Unregister from push notifications
If your app no longer needs to receive push notifications, you can unregister the device.
Use the following method to unregister the device:
Kotlin
Java
The method requires the device identifier, which should be the same as the one used when registering the device.
Handle push notifications
The DevRev SDK currently does not support automatic handling of push notifications. To open the PLuG chat and manage navigation internally, you must pass the message payload received in the notification to the SDK.
Kotlin
Java
To extract the notification payload, do the following:
-
In Firebase Cloud Messaging (FCM), when a push notification is received, it triggers the
onMessageReceived
function in yourFirebaseMessagingService
class. -
This function receives a
RemoteMessage
object as a parameter, which contains the notification data. -
The
RemoteMessage
object has adata
property, which is a map containing key-value pairs of the notification payload. -
To extract a specific piece of data from the payload, use the key to access the value in the data map.
-
To retrieve the “message” from the payload:
Kotlin
Java
For example:
Kotlin
Java
Troubleshooting
-
Issue: Encountering problems with DevRev SDK integration.
Solution: Verify the correct SDK dependency setup in the project. EnsuremavenCentral
is accessible from the IDE, and confirm accurate detection of the selected DevRev PLuG SDK version. -
Issue: The
showSupport()
function or XML button is unresponsive.
Solution: Confirm that user identification is performed before using theshowSupport()
function or XML button. -
Issue: Incorrect operation due to
App ID
andsecret
misconfiguration.
Solution: Ensure correct functionality by double-checking that bothApp ID
andsecret
values are accurately configured in your application or sample app.