Wix Answers Mobile SDK for Android

The Wix Answers Android SDK enables your users to access the Wix Answers widget from inside your application. Your users will have access to all of the existing widget features:
  • Live chat
  • KB articles
  • Contact form
  • Request callback
  • and more!

Setup

  1. Download the SDK's AAR file from here.
  2. Select File > New Module. In the new window, select Import .JAR/.AAR Package and select the AAR file that you downloaded.
  3. Ensure that ':wixanswers-sdk' is added in your project level settings.gradle file.
  4. In your project level build.gradle file, add the following line in the dependencies block:
    • classpath 'com.google.gms:google-services:4.3.3'
  5. Add the following permissions to your AndroidManifest.xml, if they do not already exist:
    • <uses-permission android:name="android.permission.INTERNET" />
    • <uses-permission android:name="android.permission.VIBRATE"/>
    • <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  6. Create a Firebase project to handle push notifications (if you don't already have one):
    1. Open http://firebase.google.com and create a new project.
    2. After you set up your project, create a new Android Application and follow the steps of the wizard.
    3. Select Project Settings (top left corner, next to Project Overview).
    4. In the Cloud Messaging tab, copy the Server Key field value and send it to mobilesdk@wixanswers.com together with your tenant name.
  7. In your app level build.gradle file, in the dependencies block, add the following packages:
    • implementation 'com.google.firebase:firebase-messaging:17.+'
    • implementation project(path: ':wixanswers-sdk')
  8. In the same file, add the following line to the end. If it already exists in your build.gradle file, move it to the end (outside the dependencies block):
    • apply plugin: 'com.google.gms.google-services'
  9. Sync your project with the Gradle files.

Usage

  1. In your application class, import the WidgetSDK package:
    • import com.wixanswers.widgetsdk.*;
  2. Call the init method in the onCreate method of your application class to set up your connection to Wix Answers. The init method accepts four arguments:
    • The Application instance - this
    • Account name
    • Widget ID
    • An authentication callback - The Wix Answers Android widget will call this callback to receive a secure token. You must implement this callback to call your server to perform the authentication. See this article for details. The callback will receive an object with a setUserToken that accepts a string. Once you acquire a token for the current user, use that method to set it in the SDK.
To find your account name and widget ID, open the Widget configuration page and edit a specific widget in the Wix Answers back office. Copy the information from the URL, for example: https://[ACCOUNT_NAME].wixanswers.com/app/settings/widgets/[WIDGET_ID]/content/en
To call the init method, add the following code in your application delegate file:
1
2
3
4
5
6
7
8
9
10
11
12
WidgetSDK.init(this, "myAccountName", "myWidgetID", new WidgetSDK.OnWidgetUserTokenRequest() {
  @Override
  public void onRequest(final WidgetSDK.OnWidgetUserTokenResponse tokenResponse) {
    // Authenticator is an example class that Authenticates the current use and retrieves a token
    new Authenticator(new Authenticator.AsyncResponse() {
      @Override
      public void processFinish(String token) {
        tokenResponse.setUserToken(token);
      }
    }).execute();
  }
});
3. Now that the user is authenticated, you can call WidgetSDK.openWidget() to open the Wix Answers Chat interface in a separate Android Activity.

Opening Chat From a Push Notification

To open Chat Activity when a user selects a chat push notification, use the following code (in your onResume Lifecycle method or any place you see fit):
1
2
3
if (WidgetSDK.wasAppOpenedFromNotification()) {
  WidgetSDK.openWidget();
}

Listening for New Messages

To run an action whenever a new chat message arrives (showing a toast or a badge), use the onNewMessage method:
1
2
3
4
5
6
7
8
WidgetSDK.onNewMessage(new WidgetSDK.OnWidgetNewMessage() {
  @Override
  public void onNewMessage(String content) {
    Log.i("APP", "Received a new chat message:" + content);
    // TODO: show a Toast
    // TODO: show a badge
  }
});

Running an Action When the SDK Init Phase Completes

To run an action when the SDK is fully initialized, run the following:
1
2
3
4
5
6
WidgetSDK.onInitCompleteRequest(new WidgetSDK.OnInitCompleteRequest() {
  @Override
  public void onRequest() {
    Log.i("SDK", "Init complete!");
  }
});
Note
Configure the onInitComplete callback before calling WidgetSDK.init.