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 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. This 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.
    • Locale
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 this method, add the following code in your application delegate file. Replace "<locale>" with a language code string to load the widget in that language. If you remove this parameter, the default language is English ("en").
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();
  }
}, "<locale>");
3. Now that the user is authenticated, you can call WidgetSDK.openWidget() to open the Wix Answers Chat interface in a separate Android Activity.

Methods

init(this, account_name:string, widget_id:string, auth_callback:function, locale:string)

Set up connection to Wix Answers.

Return: None

See information about this method above.
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();
  }
}, "<locale>");

onInitComplete(callback:function)

Run a function when a initialization is complete. Cal this before calling init.

Return: None
1
2
3
4
5
6
WidgetSDK.onInitComplete(new WidgetSDK.OnInitComplete() {
  @Override
  public void onRequest() {
    Log.i("SDK", "Init complete!");
  }
});

onLoaded(callback:function)

Run a block or code after the widget is loaded. Call this before init.

Return: None
1
2
3
4
5
6
WidgetSDK.onLoaded(new WidgetSDK.OnLoaded() {
  @Override
  public void onLoaded() {
    // Code Goes Here...                  
  }
});

onNewMessage(callback:function)

Run a function when a new message arrives in chat.

Return: None
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
  }
});

openWidget()

Display the widget.

Return: None
1
2
3
if (WidgetSDK.wasAppOpenedFromNotification()) {
  WidgetSDK.openWidget();
}

setFeaturedArticles(articles:list of article IDs)

Dynamically set the featured articles in the widget. You must call this in an onLoaded block before displaying the widget (openWidget).

Return: None
1
2
String[] articles = { "fef78571-7a8c-4fa9-b48c-8f106fa16ca8" };
WidgetSDK.setFeaturedArticles(articles);

wasAppOpenedFromNotification()

Check if the widget was opened from a push notification.

Return: Boolean
1
2
3
if (WidgetSDK.wasAppOpenedFromNotification()) {
  WidgetSDK.openWidget();
}