From Ninja Metrics Developer Hub

IntegrationExamples: Android

Getting Started
To get started with our simple Android test implementation, you will need the Android SDK, an Eclipse environment with Android Developer Tools (ADT) configured, and our Android library. The simplest way to get a configured environment is to simply download the ADT bundle.

  1. Download and extract the Android SDK with ADT bundle from http://developer.android.com/sdk/index.html.
  2. Our implementation targets API 17, which can be obtained through the SDK Manager. Run android.bat in the \sdk\tools subdirectory. This will launch the Android SDK Manager with appropriate settings.
  3. Expand the Android 4.2.2 (API 17) item, check the box next to SDK Platform, then click Install. After it completes, close the SDK manager.
  4. Pull our Android library and test implementation from https://bitbucket.org/ninja_metrics/kapi-android-lib.

Building the Android library and test implementation
With Eclipse+ADT configured with API 17, you're now ready to build.

  1. Start Eclipse. If you installed the full ADT bundle, it's in the \eclipse subdirectory.
  2. Go to File→Import. Chose Git?Projects from Git. Add the root directory of kapi-android-lib, and click through to Finish. Import both projects, kapi-java-lib and NinjaMetricsTest.
  3. Expand the kapi-java-lib project in Package Explorer, right click build.xml at the root, and Run As an Ant Build.
  4. Refresh your view of the project and you should see kapi.jar in the root. Drag this to the assets folder under the NinjaMetricsTest project.
  5. Run Project→Clean and clean the NinjaMetricsTest project. This will force re-creation of Android generated files and all errors should now disappear. If you still receive errors about a missing target, “android-17,” try closing ADT and re-running the SDK Manager steps to install the Android 4.2.2 SDK.
  6. If you would like to use your own account for the example, open the NinjaMetricsTest\res\values\kapi_strings.xml file. Change to the kapi_strings.xml tab and update the three helper entries at the top of the file with your own client id, app id, and password.

Create a Virtual Device
If you do not have a physical device to test with, you'll now need to configure the Android emulator.

  1. Go to Window→Android Virtual Device Manager.
  2. Create a new virtual device. Choose “Nexus S” for the device and choose the latest API you have for the Target.
  3. Highlight your new device in the list, and click “Start,” then “Launch.” The emulator will launch and then boot. It may take several minutes, particularly on this first launch, for the boot up process to finish.

Running the test implementation
You can see sample implementations of many of the supported events in the src\com.ninjametrics.kapi.ninjametricstest package. Each test is separated into an individual Java class, and all the tests are presented as a list within the application.

  1. Right-click the NinjaMetricsTest project and Run As an Android Application. There will be a delay as the package is built and copied to your emulator or device.
  2. After the console indicates that the application was launched successfully, you may have to unlock the screen on your Android emulator or device.
  3. When the application opens, you should see your client id, application id, and password filled in. If you do not, see the step about editing your kapi_strings.xml file above.
  4. Swipe up or down to scroll through the available tests. Clicking a test will bring up some default values for the test, which can be adjusted before you click Submit to run the test event.

Debugging the test implementation
Setting up to step through the code running on the emulator only takes a few steps.

  1. With the application running, switch back to Eclipse and go to Window→Open Perspective→DDMS.
  2. In the Devices pane, highlight the com.ninjametrics.kapi.ninjametricstest process and click the little green bug at the top of the pane to attach to that process.
  3. Now that the debugger is attached, you’ll be able to set breakpoints and begin stepping through code.
Retrieved from https://developer.ninjametrics.com/IntegrationExamples/Android
Page last modified on January 20, 2014, at 07:40 PM