Home > Devices > Fire Phone

Understanding the Native-Code HeadTracking API

Introduction

The native-code HeadTracking API is composed of one prebuilt static library named libheadtracking_client.a and 4 C++ header files:

  • HeadTrackingEvent.h
  • HeadTrackingConfiguration.h
  • HeadTrackingManager.h
  • HeadTrackingPoller.h

In order to integrate with the native-code HeadTracking API from a standard native app, you simply need to declare a LOCAL_STATIC_LIBRARIES dependency on libheadtracking_client.a within your Android.mk file. This is achieved by first defining the HeadTracking library as a PREBUILT_STATIC_LIBRARY module and setting up a dependency on that module from your module.

The following is an example:

LOCAL_PATH :=  $(call my-dir)
include  $(CLEAR_VARS)
   LOCAL_MODULE    := YourModuleName
   LOCAL_SRC_FILES  := YourSourceFile.cpp
   LOCAL_LDLIBS    := -llog -landroid
   LOCAL_STATIC_LIBRARIES  := libheadtracking_client
include  $(BUILD_SHARED_LIBRARY)
include  $(CLEAR_VARS)
   LOCAL_MODULE    := libheadtracking_client
   LOCAL_SRC_FILES  := PathToLibrary/libheadtracking_client.a
   include  $(PREBUILT_STATIC_LIBRARY)

You can then reference the classes and methods declared in the header files from within your sources and build the native component of your app by using the NDK-build utility.

For a fully working example, see the NativeHeadTrackingSample sample app.

The NativeHeadTrackingSample Sample App

NativeHeadTrackingSample is a native-code sample app for the Fire phone that illustrates the native-code HeadTracking API and its correct usage. The sample includes the following files:

  • jni/main.cpp
  • jni/Android.mk
  • jni/Application.mk
  • AndroidManifest.xml
  • res/values/strings.xml

To build and run the sample, ensure that your development environment is set up as described in Setting Up Your Development Environment. You also need to download and install the Android NDK for your platform, available from Android NDK. Then perform the following steps to build and run the sample.

To build NativeHeadTrackingSample:

  1. In a terminal, navigate to <ANDROID_SDK>/add-ons/addon-amazon_fire_phone_sdk_addon-amazon-17/ndk/samples/NativeHeadTrackingSample.
  2. Copy the libs and include directory from <ANDROID_SDK>/add-ons/addon-amazon_fire_phone_sdk_addon-amazon-17/ndk/platforms/android-17/arch-arm/usr to the jni directory.
  3. Build the native component:
    > <ANDROID_NDK>/ndk-build
  4. Build and install the app using Gradle:
    For UNIX or OSX,
    > ./gradlew installDebug
    For Windows
    > gradlew.bat installDebug

Native-Code HeadTracking API Reference Documentation

For the reference documentation for the HeadTracking API, see Native HeadTracking API for Fire Phone.