Versions Compared

Key

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

Introduction

This document explains how to add the Appoxee code to your application code (step 3 of the Appoxee Android SDK integration process).

Info
titleUsing Google Play Services

If you choose to use Appoxee SDK uses Google Play Services, you need to know the following :

To test your app when

which is supported on devices using the Google Play

services SDK, you must use either:A compatible Android device that runs

store, and are running Android 2.3

or higher and includes Google Play Store.
  • The Android emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or higher.
  • To make the Google Play services APIs available to your app:

    1. Copy the library project at <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/ to the location where you maintain your Android app projects.
    2. Import the library project into your Eclipse workspace (if you use Eclipse) : Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
    3. In your app project, reference Google Play services library project.

      Note: You should be referencing a copy of the library that you copied to your development workspace—you should not reference the library directly from the Android SDK directory.

    4. Use the AndroidManifest.xml written below for GooglePlayServices integration
  • To prevent ProGuard from stripping away required classes, add the following lines in the<project_directory>/proguard-project.txt file:

     

    Code Block
    languagetext
    titleProGuard
    -keep class * extends java.util.ListResourceBundle {
        protected Object[][] getContents();
    }
    
    -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
        public static final *** NULL;
    }
    
    -keepnames @com.google.android.gms.common.annotation.KeepName class *
    -keepclassmembernames class * {
        @com.google.android.gms.common.annotation.KeepName *;
    }
    
    -keepnames class * implements android.os.Parcelable {
        public static final ** CREATOR;
    }

     

     

    We now have 2 options of Integration : Explicit & Implicit.

    Explicit integration enables (through inheritance and interface implementation) an automated process of sending analytics data to Appoxee and to control API Calls (Tags, Alias etc.) through an Observer (Callback Methods implementation in your code which are declared in AppoxeeObserver) that will indicate if the SDK is done loading and ready to process the API Calls. This will save the trouble of checking if the SDK is ready through a separate thread or any other means.

    Explicit Integration is the preferred way.

    Implicit Integration is a form of Integration that can be done if your code doesn't allow you to inherit from Appoxee and to implement it's Observer Interface. Both Integrations are explained below.

    and above.

    For more info / troubleshooting see Google Play Services documentation: https://developers.google.com/android/guides/setup

     

    The code sections below use the following typographic conventions:

    • Regular text - existing code: You should already have this code in your project by default. No changes are required.
    • Bold text - new code: Make sure you add this Appoxee code to your app code.
    • Green text - comments: A comment describes the code that follows it and notes special issues you should pay attention to. Please read the comments carefully.
    • Blue text - AndroidManifest.xml updatesThe changes you should make in the app's AndroidManifest.xml file.

    Integration Instructions

    The integration has two parts:

    1. Source code integration - Integration into the source code which can be done in two ways:
      1. Explicit - Explicit integration enables (through inheritance and interface implementation) an automated process of sending analytics data to Appoxee and to control API Calls (Tags, Alias etc.) through an Observer (Callback Methods implementation in your code which are declared in AppoxeeObserver)  that will indicate if the SDK is done loading and ready to process the API Calls. This will save the trouble of checking if the SDK is ready through a separate thread or any other means. Explicit Integration is the preferred way.
      2. Implicit - Implicit Integration is a form of Integration that can be done if your code doesn't allow you to inherit from Appoxee and to implement it's Observer Interface. Both Integrations are explained below.
    2. Manifest Integration and Advanced Options (Inbox / DeepLink (URLScheme) ) - Needed in either case of Code Integration (Explicit/Implicit)
    Eclipse Users : When compiling a production APK file with ProGuard and Appoxee
    Note
    Note

    If you are using Eclipse and ProGuard, enter the following lines into the file "proguard-project.txt"

    Code Block
    languagetext
    titleProGuard in Eclipse
    linenumberstrue
    -dontwarn
    # OrmLite uses reflection
    -keep class com.j256.**
    -keepclassmembers class com.j256.** { *; }
    -keep enum com.j256.**
    -keepclassmembers enum com.j256.** { *; }
    -keep interface com.j256.**
    -keepclassmembers interface com.j256.** { *; }
    -keepattributes Signature
    -keepattributes *Annotation*
    -keepclassmembers class * { public <init>(android.content.Context); }

     

    In order to avoid these additions in each activity, you can simply extend AppoxeeBaseActivity instead of Activity. (AppoxeeBaseActivity extends Android’s FragmentActivity and contains the onStart() & onStop() calls)

     

    Source code integration

    Option A: Explicit Integration (with Observer) : 

    ...

     

    Source code integration

    On your main activity class  add the following code to Activity life-cycle callback methods:

    Code Block
    languagejava

    ...

    linenumberstrue
    @Override
    protected void onCreate(

    ...

    Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
    		 ...
    		 new initAsync(getApplicationContext(),"APP_KEY",
                         "SECRET_KEY", true, "com.package.MainActivity"

    ...

    ).execute();
    		AppoxeeManager.setDebug(true);

    ...

     

     

    Make sure that the following methods are implemented and contain Appoxee's method calls :

    Code Block
    languagejava
    linenumberstrue
        @Override
        protected void onResume()
        {
         super.onResume();
         // If Inbox implemented and you have a method for updating your inbox’s 
         // Badge
         updateMsgBadge();
        }
    
    
     @Override
     public void onRegistrationCompleted() {
      // TODO Auto-generated method stub
         Utils.Debug("Can perform all API Calls");
     }
    
    
     @Override
     public void onMessagesUpdateCompleted() 
     {
     // If Inbox implemented and you have a method for updating your inbox’s 
     // Badge
        Utils.Debug("Can update Badge");
        updateMsgBadge();
     }
    
    
    

     

     

    ...

    To fully use Appoxee’s Analytics , all of your activities should implement onStart() & onStop in the actvities code :

    ...

    languagejava
    linenumberstrue

    ...

    	//set 'false' to get less debug logs 	
    		...
    }
     
    @Override  
    protected void onStart() {
    

    ...

    	super.onStart();
    

    ...

    	Appoxee.onStart();
    	...
    }

    ...

    
    
    @Override
    protected void onStop() {
    

    ...

    	Appoxee.onStop();

    ...

    	
    	super.onStop();
    	...
    }
    

    ...

     

     

    In order to avoid these additions in each activity, you can simply extend AppoxeeBaseActivity instead of Activity. (AppoxeeBaseActivity extends Android’s FragmentActivity and contains the onStart() & onStop() calls)

    Option B: Implicit Integration (without using Observer)

    ...

    In your main activity class onCreate() method enter the following code :

    Code Block
    languagejava
    linenumberstrue
    ...
    new initAsync(getApplicationContext(),"APP_KEY",
                         "SECRET_KEY", true, "com.package.MainActivity").execute();
    AppoxeeManager.setDebug(true);
    Appoxee.parseExtraFields(getIntent().getExtras());
    setContentView(R.layout.main);
    ...
    
    

     

     

    Make sure that the following methods are implemented and contain Appoxee's method calls :

     

    Code Block
    languagejava
    linenumberstrue
    @Override  
    protected void onStart() 
    {
       super.onStart();
       Appoxee.onStart();
    }
    
    @Override
    protected void onStop()
    {
       super.onStop();
       Appoxee.onStop();
    }
    
    @Override       
    protected void onNewIntent(Intent intent) 
    {
       super.onNewIntent(intent);
       Bundle bundle = intent.getExtras();
       Appoxee.parseExtraFields(bundle);
    }
    
    @Override 
    protected void onResume()
    {
      super.onResume();
      // If Inbox implemented and you have a method for updating your inbox’s 
      // Badge
      updateMsgBadge();
    }
    
    

     

     

    ...

    You may want to add observer to Appoxee callbacks.

    To do so, you'll have to implement the AppoxeeObserver interface and implement callbacks.

    Example:

    Code Block
    public class AppoxeeExampleActivity extends Activity implements AppoxeeObserver{
    	
    	...
     
    	@Override
    	public void onRegistrationCompleted() {
    		//from this point on, Appoxee API is avaliable
    	}
    
    	@Override
    	public void onMessagesUpdateCompleted() {
    		//callback for getting inbox messages
    	}
    
    	@Override
    	public void onRegistrationFailure() {
    		//Huston, we have a problem... 
    	}
    
    	@Override
    	public void onGeoRegistrationFailure() {
    		//This is for future support ;)
    	}
     
    	...
    
    }

     

     

    Note

    All Appoxee API calls will fail until Appoxee has finished initialization. When Integrating Appoxee and choosing not to use an Observer

    ...

    (and sometimes when do), you may consider checking if

    Code Block
    Appoxee.isReady() ==

    ...

     true 

    before doing such operations.


    Note

    To fully use Appoxee’s Analytics , all of your activities should implement onStart() & onStop in the actvities code :

    Code Block
    languagejava
    linenumberstrue
    @Override  
    protected void onStart() 

    ...

    {
    

    ...

    	super.onStart();
    

    ...

    	Appoxee.onStart();
    	...
    

    ...

    }
    
    

    ...

    @Override
    protected void onStop()

    ...

     {
    

    ...

    	Appoxee.onStop();

    ...

    	
    	super.onStop();
    

    ...

    	...
    }
    

    ...

     

    Advanced Options (Inbox / DeepLink (URLScheme) ) :

    ...