Mobile SDK for Android

Modified on Tue, 12 Nov at 4:00 PM

Mobile SDK for Android

With TeamViewer Software Development Kit (SDK) you can utilize full Assist AR functionality and provide the best AR remote support experience to your customers by embedding AR remote assistance capabilities within your own mobile apps.

The SDK enables you to have secure and GDPR compliant connections to your customer's devices. 

This article applies to all TeamViewer Assist AR users.

Prerequisites 

  • Android 5.0 and higher  
  • An existing TeamViewer account 

If you don't have a TeamViewer account, follow the steps below to create one: 

  1. Go to https://login.teamviewer.com/ and click Sign Up
  2. Complete the steps to create an account and validate your email address. 

Generate an API key 

1) Go to https://login.teamviewer.com/ and sign in using your TeamViewer account.

2) On the bottom of the page, click Apps.

image001.png

3) Click the Create App button.

image002.jpg

4) Activate Mobile SDK Token, enter a name, and (optional) add a short description.

5) Activate Android.

image003.png

6) Click Create.

Your token is displayed when opening the created app:

image004.jpg

Copy this token into your clipboard and paste it to a secure place.

?IMPORTANTDo not share this token with anyone!

Get the TeamViewer Mobile SDK

SDK is available for customers with an Assist AR Professional license and is distributed by the TeamViewer Support team. 

 

Integrate Your TeamViewer Mobile SDK  

1) TeamViewer Mobile SDK for Android contains below files: 

  • TeamViewerSdk.aar (TeamViewer Mobile SDK) 
  • AssistARSessionUI.aar (only needed if you want to establish AssistAR Session using SDK) 
  • ScreenSharingSdk-docs (TeamViewerSdk documentation) 
  • AssistARSessionUI-docs (AssistARSessionUI documentation) 
  • The demo app is available under https://github.com/teamviewer/TravelApp/

2)  Create a libs folder under your app directory and copy the *.aar files there. 

?Note: The SDK supports the following architectures: armeabi-v7a, arm64-v8a, x86, x86_64. 

3) Enable ViewBinding and add following dependencies to your app’s build.gradle:

android { 
 
   buildFeatures { 
      viewBinding true 
   } 
} 
 
dependencies { 
   implementation files('libs/TeamViewerSdk.aar') 
   implementation files('libs/AssistARSessionUI.aar') //(Add only if you plan to use AssistAR(AssistAR) Session 
    
// Add dependencies of AssistARSessionUI.aar(Add only if you plan to use AssistAR Session): 
   runtimeOnly "androidx.camera:camera-camera2:1.0.2" 
   runtimeOnly "androidx.camera:camera-lifecycle:1.0.2" 
   runtimeOnly "androidx.constraintlayout:constraintlayout:2.0.4" 
   runtimeOnly "androidx.fragment:fragment-ktx:1.3.6" 
   runtimeOnly "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1" 
   runtimeOnly "androidx.work:work-runtime-ktx:2.5.0" 
   runtimeOnly "com.google.android.material:material:1.4.0" 
   runtimeOnly "de.javagl:obj:0.3.0" 
   runtimeOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31" 
   runtimeOnly "com.google.android.gms:play-services-mlkit-text-recognition:17.0.0" 
   runtimeOnly "com.squareup.picasso:picasso:2.8" 
}

To get an updated list of dependencies please check AssistARSessionUI-docs/index.html which will be part of the SDK package you receive from TeamViewer. 

4) Build the TeamViewerSdk object: 

 teamViewerSdk = TeamViewerSdk.Builder(context) 
        .withToken(SDK_TOKEN) 
        .withAuthenticationCallback(sdkAuthenticationCallback) 
        .withSessionCallback(sdkSessionCallback) 
        .withErrorCallback(sdkErrorCallback) 
        .withOnlineStateCallback(onlineStateCallback) 
        .withMicInitiallyMuted(true) 
        .build() 
} 

The above example shows the creation teamViewerSdk object using SDK_TOKEN (use SDK_TOKEN created above in step 7 of “Generate API Key Section”) 

Please visit ScreenSharingSdk-docs/com/teamviewer/sdk/screensharing/TeamViewerSdk.Builder.html to learn more details about these builder methods.  The documentation will be part of SDK package you receive from TeamViewer. 

5) Connect to a session code 

The shared SDK provides a method for establishing a connection to a session code. This session code can be of two types: 

  • Remote Support or  
  • Assist AR 

6) Create session codes in your TeamViewer Client (select the type Remote Support or AssistAR based on the session you want) or via the TeamViewer REST API.

teamViewerSdk.connectToSessionCode(sessionCode)

Once sessionCode is online, a connection can be initiated from TeamViewer Client side. 

The session code state can be checked using OnlineStateCallback

(ScreenSharingSdk-docs/com/teamviewer/sdk/screensharing/TeamViewerSdk.Builder.html#withOnlineStateCallback
(com.teamviewer.sdk.screensharing.OnlineStateCallback). 

OnlineStateCallback is useful to get notified of the SDK online/offline/connected state:

private val onlineStateCallback = OnlineStateCallback { onlineState -> 
    val isSdkOnline = OnlineStateCallback.OnlineState.OFFLINE 
    val isSdkOffline = OnlineStateCallback.OnlineState.ONLINE 
    val isSessionCodeConnected = OnlineStateCallback.OnlineState.CONNECTED 
}

ErrorCallback is useful to handle error codes sent by the SDK in case the session code is invalid, expired, or closed.

(ScreenSharingSdk-docs/com/teamviewer/sdk/screensharing/TeamViewerSdk.Builder.html#withErrorCallback
(com.teamviewer.sdk.screensharing.ErrorCallback))
private val sdkErrorCallback = ErrorCallback { errorCode -> 
    val invalid = errorCode == ErrorCallback.ErrorCode.SESSION_CODE_INVALID 
    val expired = errorCode == ErrorCallback.ErrorCode.SESSION_CODE_EXPIRED 
    val closed = errorCode == ErrorCallback.ErrorCode.SESSION_CODE_CLOSED 
}

Reacting to incoming connections

The SDK provides callback methods for reacting to incoming connection events. 

1) AuthenticationCallback 

AuthenticationCallback is useful to handle incoming connections. 

AuthenticationData parameter contains the name of the supporter and a callback function to allow or reject the incoming connection.

private val sdkAuthenticationCallback = object : AuthenticationCallback { 
    override fun onAuthentication(data: AuthenticationData?) { 
  //set true to accept call, set false to reject call 
        data?.callback?.onAuthenticationResult(true) 
        Logging.info(TAG, "TeamViewer connected to ${data?.partnerName}") 
    } 
 
    override fun onAuthenticationCanceled() { 
        // Is called when TeamViewer Authentication was cancelled from TeamViewer client/expert side 
    } 
}

If the incoming connection is accepted, the corresponding TeamViewer connection is established. 

  • For the ScreenShare connection, a prompt for microphone permission is shown to the user. (Asking for microphone permission for ScreenShare Session should be implemented by App Developer in SessionCallback.) 
  • For the Assist AR connection, the system permissions for camera and microphone access are shown. If the user allows this, the AR session is started. 
  • If the client/expert sends file to the server, storage permission is asked to move files to Downloads directory after the end of the session . 
  • There is bi-directional VoIP communication between the user and the supporter. The initial mic state is unmuted, but this can be changed using the sdk Builder method withMicInitiallyMuted(boolean muted). 

 

2) SessionCallback 

Once the connection is initiated on the TeamViewer side, the SDK gets notified about this connection attempt via SessionCallback. 

I) AssistARSession(AssistARSession): 

For AssistAR sessions make sure to ->

  • Set AssistARSessionUI.currentSession = session in onSessionStarted()  
  • launch AssistARSessionActivity as mentioned in below code. 
  • Set AssistARSessionUI.currentSession = null in onSessionEnded()


private val sdkSessionCallback = object : SessionCallback { 
    override fun onSessionStarted(session: TeamViewerSession?) { 
        if (session is AssistARSession) { 
            AssistARSessionUI.currentSession = session 
            val intent = AssistARSessionUI.createIntentForAssistARSessionActivity(context, "StorageFolderName") 
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK 
            context.startActivity(intent) 
        } 
    if (session is ScreenSharingSession) { 
//Request microphone permission if you intend to use VOIP with ScreenShare Session 
       } 
    } 
 
    override fun onSessionEnded() { 
        Logging.info(TAG, "TeamViewer Session ended") 
        AssistARSessionUI.currentSession = null 
    } 
} 

Passing storageFolderName to the createIntentForAssistARSessionActivity method here is mandatory as this is the name of the folder where shared documents will be stored under the Downloads folder. For details check out AssistARSessionUI-docs/-pilot-session-u-i/com.teamviewer.sdk.assistarsessionui/-assist-a-r-session-u-i/create-intent-for-assist-a-r-session-activity.html 

 

II) ScreenSharingSession: 

ScreenSharingSession requires to request the microphone permission in OnSessionStarted() if you intend to use VOIP. 

 

Logging: 

Builder method withLogger(Logger callback) sets a Logger callback to which all log output from the TeamViewer Sdk is delegated to. 

To check out details for this callback and other additional callbacks available with Sdk builder please visit ScreenSharingSdk-docs/com/teamviewer/sdk/screensharing/TeamViewerSdk.Builder.html.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article