Developer Console
Thank you for your visit. This page is only available in English at this time.

DRM Sample App

This sample app shows you how to incorporate DRM license checking with the code described in DRM Overview. Exploring the sample app can give you a better sense of how to incorporate DRM in context. The sample app can run on either Fire TV or Fire tablets.

Step 1: Use the Necessary Assets

First, gather all the necessary assets for your project. Download and unzip the following:

  • DRM Sample App - Part of the Appstore SDK
  • Appstore SDK - See SDK Downloads
  • Amazon App Tester (on your Fire device) - Download the App Tester from here

You also need a AppstoreAuthenticationKey.pem file, but you can download this during Step 3 of the tutorial.

Additionally, you will need the following:

Step 2: Add the Appstore SDK JAR to the Sample App

The Appstore SDK JAR isn't automatically bundled into the DRM sample app you are about to create. (Otherwise, the sample app would become outdated with each new release of the Appstore SDK). To add the SDK JAR into the sample app:

  1. Open Android Studio and select Open an existing Android Studio project.
  2. Browse to the SampleDRMApplication folder and select it. Then click Open.
  3. Change to the Project view.

    Project view
    Project view
  4. Copy the amazon-appstore-sdk-[x].jar file.
  5. In the Android Studio project, expand app and select libs. Paste the amazon-appstore-sdk-[x].jar file into this directory.
  6. Expand the app folder and open the build.gradle file. Customize the dependency on the amazon-appstore-sdk-[x].jar file you added. For example, if the Appstore SDK is version 3.0.2, your code would look as follows:

    dependencies {
        implementation files('libs/amazon-appstore-sdk-3.0.2.jar')
    }
    
  7. Build the project by going to Build > Rebuild Project.

    It may take Android Studio a few minutes to build the project, as Gradle gets needed assets and builds the project. If Android Studio needs any specific files or libraries, you'll be prompted to download them. After installing any needed assets, Android Studio will rebuild the project.

Step 3: Add the PEM File into Your Project's Assets

To add the PEM file to the sample app:

  1. Log into the Developer Portal with your developer account.
  2. If you already have an app, go to Apps & Services > My Apps. Then click your app. (If you don't already have an app, see Log In and Add an App.)
  3. Create a new version of your app. In the area below your app's name, click Upcoming Version.

  4. Go to the APK Files tab.
  5. Click Public Key in the upper-right area.
  6. In the Public Key dialog box that appears, click the AppstoreAuthenticationKey.pem link to download the PEM file. This file contains your public key.

    PEM file link
    PEM file link
  7. Copy the AppstoreAuthenticationKey.pem file and paste it into the app/src/main/assets folder of your Android Studio project.

Step 4: Connect to Your Fire Device Through adb

Connect your computer to either a Fire TV or Fire tablet through ADB. (The sample app runs on either Fire TV or Fire tablets.) See one of the following for details:

In the sample app, note that the AndroidManifest.xml file (inside app > src > main), has the following feature defined:

<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />

Setting the touchscreen property to false to support Fire TV. Without this, Fire TV devices won't support your app.

Step 5: Install Amazon App Tester on Your Fire Device

When you're developing your app with DRM or IAP (both of which need to communicate with the Appstore), you test your app using an APK called Amazon App Tester. The Amazon App Tester app simulates the Amazon Appstore client. To set up Amazon App Tester:

  1. If you already have a previous version of Amazon App Tester installed, first uninstall it. (Note that this app is different from Web App Tester.)
  2. In your terminal or command prompt, browse to the directory where you downloaded the Amazon App Tester APK.
  3. Install the APK on your Fire device using adb:

    adb install -r amazon-app-tester.apk
    

    The -r parameter reinstalls the APK in case you already have App Tester installed.

  4. Open the Amazon App Tester app on your Fire device. To locate the installed app, see the following:

    • Fire tablets: Click the Games & Apps menu and then click Library. Next to Amazon App Tester, click Open. (If you don't see the app, check the Updates tab as well.)
    • Fire TV: Go to Settings and click Applications. Click Manage Installed Applications. Click Amazon App Tester, and then select Launch application.
  5. Click the Appstore SDK API's banner.
  6. Click DRM API Response Settings.

    If you don't see this DRM API Response Settings option, you aren't using the latest version of Amazon App Tester.

  7. Select the license status you want for the app. If you leave it at the "Default," the LICENSED status will be used.

    DRM API Response Settings
    DRM API Response Settings in App Tester

Step 6: Enter Sandbox Mode

Sandbox mode constrains calls that would normally go to the Appstore client to route to the Amazon App Tester app instead. Use this mode only for testing locally.

  1. In the same terminal where you connected to your Fire device through ADB, enter sandbox mode:

    adb shell setprop debug.amazon.sandboxmode debug
    

    (Note that if you need to exit sandbox mode, run the following: adb shell setprop debug.amazon.sandboxmode "".)

    Every time you reconnect to your Fire device through ADB, you need to reinitiate sandbox mode.

Step 7: Run Your App

  1. In Android Studio, click the Logcat tab and filter on LicenseResponse.
  2. Click the Run App button Run 'app' to run the app on your Fire device.

    The sample app has a basic screen showing the license status and nothing more. A LICENSED license status looks as follows:

    DRM sample app homescreen
    DRM sample app homescreen

    A NOT_LICENSED response looks as follows:

    License failure
    License failure
  3. You can also observe the messages logged to the console for the license status.

    Logcat filtered on LicenseResponse
    Logcat filtered on LicenseResponse

If you look in the app/src/java/com/amazon/sample/drm/ folder and open the LicenseVerificationCallback Java file, you'll see the logic for how the app handles the license verification. More details are provided in the next section.

Understanding the Sample App

The purpose of the sample app is to demonstrate how to integrate DRM. In the sample app, the onCreate() method in the MainActivity class (app/src/main/java/com/amazon/sample/drm/MainActivity.java) initiates the verifyLicense() method from the LicensingService class.

protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupApplicationSpecificOnCreate();
    LicensingService.verifyLicense(getApplicationContext(), new LicenseVerificationCallback(this));
}

The verifyLicense() method passes in two parameters: the application context (getApplicationContext()) and an implementation of LicenseVerificationCallback (new LicenseVerificationCallback(getApplicationContext())).

You can see the implementation of LicenseVerificationCallback in the LicenseVerificationCallback.java class:

public class LicenseVerificationCallback implements com.amazon.device.drm.LicensingListener {
...
}

The LicenseVerificationCallback calls the onLicenseCommandResponse method to get the license status:

public class LicensingCallback implements com.amazon.device.drm.LicensingListener {

       public void onLicenseCommandResponse(final LicenseResponse licenseResponse) {

          final LicenseResponse.RequestStatus status = licenseResponse.getRequestStatus();
          ...
       }
}

This onLicenseCommandResponse method is called by the Appstore SDK after receiving the result of the verifyLicense call from Amazon Appstore.

In this simple implementation, the app just logs the license status rather than triggering any kind of action:

public void onLicenseCommandResponse(final LicenseResponse licenseResponse) {
    final LicenseResponse.RequestStatus status = licenseResponse.getRequestStatus();
    switch (status) {
        case LICENSED:
            Log.d(TAG, "LicenseResponse status: " + status);
            break;
        case NOT_LICENSED:
            Log.d(TAG, "LicenseResponse status: " + status);
        case EXPIRED:
            Log.d(TAG, "LicenseResponse status: " + status);
            LicensingPromptHelper.showLicenseFailurePrompt(context, LicenseVerificationPromptContent.DEEP_LINK);
            break;
        case ERROR_VERIFICATION:
            Log.d(TAG, "LicenseResponse status: " + status);
        case ERROR_INVALID_LICENSING_KEYS:
            Log.d(TAG, "LicenseResponse status: " + status);
        case UNKNOWN_ERROR:
            Log.d(TAG, "LicenseResponse status: " + status);
            LicensingPromptHelper.showLicenseFailurePrompt(context, LicenseVerificationPromptContent.SHUT_DOWN);
    }
  }

The response about the license status will contain one of the following statuses:

  • LICENSED
  • NOT_LICENSED
  • EXPIRED
  • ERROR_VERIFICATION
  • ERROR_INVALID_LICENSING_KEYS
  • UNKNOWN_ERROR

In Logcat, after running the app on your Fire TV, filter on the word LicenseResponse and observe what gets logged. The license responses will allow you to check that users are authorized to run the app.

For descriptions about each license status, see License Statuses.


Last updated: Oct 18, 2021