AirWatch Android SDK implementation walkthrough

Overview

This article helps demonstrate how to add the SDK to your project. Android Studio is being used for the example project throughout this article. If you do not have a prior version of AirWatch SDK, contact your account representative to request access. 

 

Acquiring the AirWatch Android SDK

The AirWatch SDK is available via the Resources portal of myAirWatch. To download the SDK, use the following steps:

  • Download the zipped SDK files
  • Unzip the SDK files
  • The SDK libraries are located in Android SDK 1.2.1 > libs; The AirWatch SDK_1.2.1.jar and son-2.1.jar files will need to be copied to the targeted project.

 

Adding the SDK jar files to the project

These jar files are generally added to the libs directory of the project. In the same project the libs directory is located within my "App" directory.

This particular sample project structure is as follows:

/Users/support/Projects/Android/PSOAuthenticationSample/app

In the example Sample Terminal Output from the project that follows, notice the libs directory is located within the App directory. 

LibsDir.png

 

Android SDK_1.2.1.jar, gson-2.1.jar need to be manually copied to the libs directory. These files are located in the SDK that is downloaded from the AirWatch Resource portal and can be added using a file browser utility on your development machine. 

LibsInProject.png

 

After completing the preceding steps, these libraries need to be specifically added to the Android Project. Completing this will allow you to use autocompletion features of the IDE. 

  1. Right click (Windows) or cmd click (Mac) on one of the library files.
  2. Select Add as Library
    AddAsLibrary.png
  3. Click OK to add the libraries to the project.
    CreateLib.png
  4. The libraries have now been successfully added to the project. 

 

Link the Support library to your project

There are two ways to link the Support library to your project. The first method is to allow gradle to reach out and pull the jar down from the Internet (this is a preferred method). You can specify a specific version and get updates during the build process. The following screenshot is from the build.gradle file located in the "App" directory. 

GradleFile.png

 

The second option is by downloading the jar from the Internet and adding it the same way demonstrated previously for the other libraries. 

 

Add the receiver to the Manifest file (optional for SDK 1.2.1 and above)

In the following example, the AndroidManifest.xml file is located in App > src > main.

ManifestLocation.png

 

The following XML needs to be added to the manifest file for the project.

<receiver android:name="com.airwatch.sdk.AirWatchSDKBroadcastReceiver"
android:permission="com.airwatch.admin.sdk.BROADCAST" >
<intent-filter>
<action android:name="AppPackageID.airwatchsdk.BROADCAST" />
</intent-filter>
</receiver>

 

It is added within the <application> tag.

manifestwithreceiver.png

 

Implementing the AirWatchSDKIntentService class

The next step is to extend the AirWatchSDKBaseIntentService. This new class will have four callback methods within it. These callbacks will help extend some SDK functionality automatically after your Intent Service is implemented. The custom SDK Intent Service needs to be created at the application root directory and the specific implementation of each callback will need to be handled by the Developer depending on the Use case. 

NewClass.png

 

Within the new Class, import the following four classes:

  • android.content.Context
  • com.airwatch.sdk.AirWatchSDKBaseIntentService
  • com.airwatch.sdk.profile.AnchorAppStatus
  • com.airwatch.sdk.profile.ApplicationProfile

importStatements.png

 

Next, inherit from the AirWatchSDKBaseIntentService

extendService.png

 

Finally, add the following four methods that are required in our subclassed Intent Service:

  • onApplicationProfileReceived(Context context, String profileId, ApplicationProfile awAppProfile)
  • onClearAppDataCommandReceived(Context context)
  • onAnchorAppStatusReceived(Context ctx, AnchorAppStatus appStatus)
  • onAnchorAppUpgrade(Context ctx, boolean isUpgrade)

requiredMethods.png

 

Finishing Up

The basic SDK functionality has been added to the project. The application can be built and deployed to devices. At this time there is not a large amount the SDK will be performing in the application and additional implementation will be required in order to fully implement the desired use cases. In order for the application to use the SDK properly, the application will need to be pushed as a managed application to devices enrolled into AirWatch. 

Have more questions? Submit a request

0 Comments

Article is closed for comments.