Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 , and Cloud and Performance services. To enable the Appcelerator Test for a project, run the AppceletatorTest utility against either the project or APK file.

...

The following tutorial demonstrates basic setup and usage of Analytics , and Cloud , and Performance libraries in an Eclipse project. To complete the tutorial, you will need your application key for the Cloud , and Analytics , and Performance services. Download a complete version of the project.

...

  1. In Eclipse, create a new Android project with a Blank Activity.
  2. Unpack the appcelerator-sdk-android-<VERSION>.zip file.
  3. Copy the  appcelerator-sdk-android-<VERSION>.jar  file to the  libs  folder of your Android project (if you wish to use Maven or Gradle, see "Building the Application" below for setup instructions).
  4. Modify the project's AndroidManifest.xml file to include the ACCESS_NETWORK_STATEACCESS_WIFI_STATE, GET_TASKS, INTERNET, READ_LOGS, and WRITER_EXTERNAL_STORAGE user permissions and declare the  com.appcelerator.aps.AnalyticsService as a Service class, which allows the APS library to send analytic events to the APS servers while the application is in the background: 

    Code Block
    titleAndroidManifest.xml
    linenumberstrue
    languagexml
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.appcelerator.sample"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <!-- Add these permissions to enable Analytics, Cloud and PerformanceCloud -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.GET_TASKS" />
        <uses-permission android:name="android.permission.READ_LOGS"/>
        <application>
            <activity>
                ...
            </activity>
     
            <!-- Add this service to enable Analytics -->
            <service android:name="com.appcelerator.aps.APSAnalyticsService"
                android:exported="false" />
        </application>
    </manifest>
  5. Add the following import statement to the main Activity of the project: 

    Code Block
    titleMainActivity.java
    import com.appcelerator.aps.APSServiceManager;
  6. In the main Activity's onCreate()  method, add the following method call to enable the APS services.

    Code Block
    titleMainActivity.java
    languagejava
    APSServiceManager.getInstance().enable(getApplicationContext(), "APP_KEY");

    The Android application is now ready to make method calls using the APS SDK APIs.

...

  1. Open the fragment layout XML file (res/layout/fragment_main.xml) in the Graphical Layout editor.
  2. Remove the "Hello World!" label.
  3. Drag a Spinner widget, EditText widget (password text field) and Button widget into the view.

  4. In the MainActivity.java file, modify the code to save an instance of the current activity, Spinner and EditText widgets. Modify the application to bind a doClick method to the Button's onClick listener 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 , and Analytics and Performance services. 

    Code Block
    titleMainActivity.java
    linenumberstrue
    languagejava
    // Import the following packages
    import android.app.Activity;
    import android.util.Log;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Spinner;
    import java.util.HashMap;
    import org.json.JSONArray;
    import com.appcelerator.aps.APSAnalytics;
    import com.appcelerator.aps.APSCloudException;
    import com.appcelerator.aps.APSPerformance;
    import com.appcelerator.aps.APSResponse;
    import com.appcelerator.aps.APSResponseHandler;
    import com.appcelerator.aps.APSServiceManager;
    import com.appcelerator.aps.APSUsers;
    
    public class MainActivity extends ActionBarActivity {
        // Handle to current activity
    	private static Activity currentActivity;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            // Save the current activity
            currentActivity = this;
    
            APSServiceManager.getInstance().enable(getApplicationContext(), "APP_KEY");
    
            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment())
                        .commit();
            }
        }
        public static class PlaceholderFragment extends Fragment {
    
    
            // Handle to Spinner and EditText widgets
        	Spinner spinner;
        	EditText textField;
    
            public PlaceholderFragment() {
            }
    
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.fragment_main, container, false);
             
                // Bind the Button do the doClick method
                Button button = (Button)rootView.findViewById(R.id.button1);
                button.setOnClickListener(new Button.OnClickListener()
                {
                    @Override
                    public void onClick(View v){
                        doClick();
                    }
                });
     
                // Save the Spinner and EditText instances
                spinner = (Spinner)rootView.findViewById(R.id.spinner1);
                textField = (EditText)rootView.findViewById(R.id.editText1);
                // Place holder for the next tutorial steps
                populateSpinner();
                return rootView;
            }      
    
    
            // Placeholder for next tutorial steps
            public void doClick() {         	
            }
     
            public void populateSpinner() {
            }
        }
    }

...

Multiexcerpt
MultiExcerptNametesting

Testing the tutorial sample

Before testing the sample, you need to create user accounts for the application to query. To create Cloud user accounts:

  1. Login to the AMPLIFY Platform.
  2. On the Dashboard tile, select Go to Dashboard.
  3. Select your application from the Projects menu.
  4. In the left navigation bar, click Manage Data.
  5. Click Users, then the Create User button.
  6. In the Username field enter the user's username.
  7. In the Password field enter the new user's password (four-character minimum).
  8. Click Save Changes.
Info

To create a Cloud user account, you only need a username or e-mail address, and a password.

For more information about managing Cloud user accounts, see Managing Organizations.

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:

  1. Click on the Picker/Spinner. You should see a list of all the Cloud user accounts you added.
  2. 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.
  3. Go back to the Dashboard.
  4. In Dashboard, select your application from the Apps menu in the upper-left corner.
  5. 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. 
  6. In the left navbar, select Analytics.
  7. In the Real-Time view, you should see at least one active session.
  8. In the left navbar, click Events. You should see the "sample.feature.login" feature event.

...

This tutorial only covers a small portion of what the Analytics , and Cloud and Performance services can provide. For more in-depth information about these features, see the following topics:

...