- Quick tutorial
- Setting up Appcelerator Test
This guide walks through the setup of the AMPLIFY Appcelerator Services for Android applications. The AMPLIFY Appcelerator Services SDK gives you access to the Appcelerator Analytics, Cloud and Performance services. To enable Appcelerator Test for a project, run the
AppceletatorTest utility against either the project or APK file.
This document assumes you have an existing Android application and are familiar with the Android toolchain to create, build and package Android applications. The following prerequisites are also needed:
- Android SDK 2.3.x (API Level 10) or greater
- Android NDK
- Eclipse 3.6 or later with the ADT plug-in (see Android Developers: ADT Plugin), or the Apache Ant command-line tool (see Apache Ant).
Before you can use Appcelerator Services in your application you need to:
- Create an application in Dashboard
- Download the SDK and
- Get the application keys
To register an Android Java, or iOS Objective-C or Swift application in Dashboard:
- Log in to Dashboard.
- Click the Add menu (+) and select Register App for Services to open the Register App for Services form.
- In the Register App for Services form, enter an application Name, and select a Platform and Category. Optionally, you can provide a description for your application. To add application team members from the organization, click the add (+) button in the App Team list at the right.
- Click OK.
Dashboard displays the Platform Services tab for your application. In the tab, you can download the APS SDK and
appcelerator-test utility, and get code snippets to copy and paste into your application.
For more information, refer to Managing Non-Titanium Client Applications in Dashboard.
The following tutorial demonstrates basic setup and usage of Analytics, Cloud, and Performance libraries in an Eclipse project. To complete the tutorial, you will need your application key for the Cloud, Analytics, and Performance services. Download a complete version of the project.
To create a basic application using APS:
- In Eclipse, create a new Android project with a Blank Activity.
- Unpack the
- Copy the
appcelerator-sdk-android-<VERSION>.jarfile to the
libsfolder of your Android project (if you wish to use Maven or Gradle, see "Building the Application" below for setup instructions).
Modify the project's
AndroidManifest.xmlfile to include the
WRITER_EXTERNAL_STORAGEuser permissions and declare the
com.appcelerator.aps.AnalyticsServiceas a Service class, which allows the APS library to send analytic events to the APS servers while the application is in the background:
Add the following import statement to the main Activity of the project:
In the main Activity's
onCreate()method, add the following method call to enable the APS services.
The Android application is now ready to make method calls using the APS SDK APIs.
Modify the application
Customize the application's UI to display a spinner, text field and button, and add some logic to respond to user interaction. The spinner will display a list of available user accounts. The user can enter their password in the text field, then click the button to log in.
- Open the fragment layout XML file (
res/layout/fragment_main.xml) in the Graphical Layout editor.
- Remove the "Hello World!" label.
Drag a Spinner widget, EditText widget (password text field) and Button widget into the view.
MainActivity.javafile, modify the code to save an instance of the current activity, Spinner and EditText widgets. Modify the application to bind a
doClickmethod to the Button's
onClicklistener and create an empty function called
populateSpinner. You need to also import additional packages. In the following sections, you will add code to these handlers that call the Cloud, Analytics and Performance services.
Building the application
If you use Maven or Gradle as part of your build process, you will need to publish the APS SDK to your local Maven repository and add the APS SDK as a dependency to your project.
First, unzip the APS SDK and install the dependencies into your local Maven repository:
Next, add the following lines of code to your Maven or Gradle POMs:
Capture user session events
Unlike the iOS and Titanium platforms, you need to explicitly make analytic method calls in the application to send user session events to the Analytics service to capture user activity.
Use the Activity's lifetime events to track when the user is actively using your application. Call the APSAnalytics'
sendAppEnrollEvent() method in the
(), which indicates the first installation or upgrade of the application.
Before calling API calls to the APSAnalytics class, you need to get a shared instance of the APSAnalytics class using the
onResume() to call the APSAnalytics
sendAppForegroundEvent(), respectively. These two APSAnalytics methods send user session events to the APS analytics servers to track how long a user engages with your application.
Send an Analytics feature event
Besides user session events, you can also send custom analytics events, as shown in this example. There are two types of custom events: feature events and navigation events.
() function, add a APSAnalytics'
sendAppFeatureEvent() method call to send a feature event with the string " sample.feature.login ". The optional second parameter is set to null for this example, but you can send additional data as a JSON object with the event.
Query Cloud users
To use the APS Cloud component, most of the methods require a user to be logged in. This sample uses the Spinner widget to select a Cloud user accounts. To populate the Spinner values, the application needs to retrieve a list of users. Use the
method to retrieve a list of user accounts.
Every APS Cloud method includes a
handler parameter that specifies the callback to handle the server response. The callback is passed an
APSResponse object that contains response metadata (such as success or failure) and the response payload.
Login to a Cloud account
To login to a Cloud account, you need the username and password. Since the application was modified to get all available user accounts and populate the Spinner, the application needs to get the current value of the spinner and the text entered in the EditText widget. These values are passed to the
APSUsers.login() method. Modify the
doClick() method to login to a Cloud user account.
Log a handled exception
The Performance library automatically logs application crashes (unhandled exceptions) and handled exceptions to the backend Performance service. You can also leave breadcrumbs in your application, which are developer-defined text strings (up to 140 characters) that are analogous to log messages.
For example, you can replace the
Log calls in the catch statements with the APSPerformance's
calls. Instead, the application will generate a runtime exception, and then call the
logHandledException() method to log that exception to the Performance backend.
Before making API calls to the APSPerformance class, you need to retrieve a shared instance of the class using the
To the doClick method, add the following new code:
Set a username for crash logs
To help differentiate crash logs, use the APSPerformance's
method. When the application successfully logs in to the Cloud user account, the application calls APSPerformance's
Testing the tutorial sample
Before testing the sample, you need to create user accounts for the application to query. To create Cloud user accounts:
- Log in to Appcelerator Dashboard.
- In Dashboard, select your application from the APIs menu in the upper-left corner.
- In the left navigation bar, click Manage Data.
- Click Users, then the Create User button.
- In the Username field enter the user's username.
- In the Password field enter the new user's password (four-character minimum).
- Click Save Changes.
After you have created a few Cloud user accounts, build the sample and launch it on either a device or emulator.
Once the application launches:
- Click on the Picker/Spinner. You should see a list of all the Cloud user accounts you added.
- Select a user account from the Picker/Spinner and enter that user's password. Click the Button. In the log output, you should see an info log that login command was successful or not.
- Go back to the Appcelerator Dashboard.
- In Dashboard, select your application from the Apps menu in the upper-left corner.
- In the left navbar, click Performance, then Handled Exceptions. You should see the "Something happened..." exception in the list.
- In the left navbar, click Search by User. Enter the username of the account that successfully logged in. Click the username. You should see a crash report for the user.
- In the left navbar, select Analytics.
- In the Real Time view, you should see at least one active session.
- In the left navbar, click Events. You should see the "sample.feature.login" feature event.
Next Steps for Appcelerator Analytics, Cloud and Performance
This tutorial only covers a small portion of what the Analytics, Cloud and Performance services can provide. For more in-depth information about these features, see the following topics:
- APS Analytics for Android
- AMPLIFY Appcelerator Platform Services SDK for Android Mobile Backend Services
- APS Performance for Android
Setting up Appcelerator Test
Before you can use Appcelerator Test, you need to configure it to enable it to connect to the Test service. To do this you run a small Java utility that makes some changes to your AndroidManifest.xml file. In particular, it adds some required permissions, as well as an Intent Filter and Service. Lastly, the tool registers your application with the external Test service, so that it's authorized for use.
Set up the application
To setup your application to use Appcelerator Test, download and run the
- Download the
appcelerator-testUtility and copy your Appcelerator Test application key from the Appcelerator Dashboard. (For instructions, see Managing Non-Titanium Client Applications in Dashboard.)
- Unpack the file to a common location. You will need to use this utility to enable Appcelerator Test for each of your applications.
You can run the appcelerator-test utility either against an Android project (static instrumentation), or an APK file.
To run the appcelerator-test utility against an APK file, first export your project as an APK file, then run the following command, and install the APK file to a device or emulator:
To run the appcelerator-test utility against a project, run the following command, then build the project and install the application to a device or emulator:
This command modifies the Android Manifest file to require extra user permissions, and add an Intent Filter and Service to the application. The final manifest file should look similar to the one below:
Install the TouchTest Agent
To run tests on a device you need to install the TouchTest Agent a light-weight software agent that controls the device during test recording and playback. Once installed you also need to register your device with the Test service, and have the device approved by an administrator (see Approving devices and simulators).
The TouchTest Agent application supports devices running Android 2.3.3 and later, and Android simulators running 2.3.5 and later. The install steps are the same for Android devices and emulators.
To install TouchTest Agent on an Android device or emulator:
- Point your device's or emulator's web browser to the TouchTest Agent URL ().
- In the login form enter your enter AMPLIFY Appcelerator Services credentials. You must append your organization ID to your login name.
- Click Tap Here to Download TouchTest Agent.
- Open the APK file that was downloaded to install the TouchTest Agent.
- Open the TouchTest Agent application.
- In the TouchTest Agent URL field enter the TouchTest Agent URL and click Go.
- Enter your AMPLIFY Appcelerator Services credentials. You must append your organization ID to your login name.
- On successful login, enter a name for your device and click Submit for Approval.
- Once the device has been approved, the TouchTest Agent displays its current connection status to the Test web service, as well as the current TouchTest URL, user name, and TouchTest Agent build number.
Record a test clip
A clip is the basic building block of a test. You create clips in the Clip Editor. Clips are composed of App Actions - taps, gestures, text inputs, and so forth - that simulate actions a user take in an application. When you record a test clip, the actions you take on a device are automatically added as App Actions in the test clip.
For example, the following screenshot shows a test clip containing four recorded actions: a tap operation, followed a type operation, followed by two more tap operations.
Typically a recorded test clip is a starting point for you to refine, add validations, inputs, outputs and so forth.
To record a test clip:
- Open Appcelerator Dashboard and click the Test tab.
Select the application to test from the Application menu in the upper-left corner.
- With your application selected, on the Central tab select Clips in the left navigation, then click the New button. The Clip Editor opens a new untitled clip.
- In the Clip Editor, click the Record menu and select Record Mobile App.
In the Choose a Device Agent and Mobile App dialog select the test device from the upper pane, and the application to test, and click Record.
- The test application launches on the device. Perform the following actions on the device:
- Click the Spinner widget.
- Select a user account.
- Click the EditText widget.
- Enter the user's password.
- Click Done on the software keyboard.
- Click the Button widget. You should see the following output in the test clip:
- Click the Record button in the Test tab in Dashboard again to stop recording.
- Click Save or Save As in the toolbar, give the clip a name or accept the default, and click Save.
To playback a test clip that you've recorded, it needs to be added to a test composition. For simplicity, you can playback the clip immediately by clicking the Play button and select Play in Composition in the test clip.
The clip is added to a draft composition and starts playing. Once the playback completes, results display in the test composition.
Next Steps for Appcelerator Test
This tutorial only covers the very basics of using the Appcelerator Test service. For more in-depth information, see Appcelerator Test. For more information about the
appcelerator-test utility, see Appcelerator Test CLI Reference.