Introduction
This document explains how to add the Appoxee code to your application code (step 3 of the Appoxee Android SDK integration process).
Using Google Play Services
If you choose to use Google Play Services, you need to know the following :
To test your app when using the Google Play services SDK, you must use either:
- A compatible Android device that runs 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:
- 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. - 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.
- 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.
- Use the AndroidManifest.xml written below for GooglePlayServices integration
- Copy the library project at
- To prevent ProGuard from stripping away required classes, add the following lines in the
<project_directory>/proguard-project.txt
file:ProGuard-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.
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 updates: The changes you should make in the app's AndroidManifest.xml file.
Integration Instructions
The integration has two parts:
- Source code integration - Integration into the source code which can be done in two ways:
- 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.
- 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.
- 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 , enter the following lines into the file "proguard-project.txt"
-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) :
- Your MainActivity needs to extend AppoxeeBaseActivity and implement AppoxeeObserver
- Your MainActivity onCreate() method should contain this code : onCreate()
... new initAsync(getApplicationContext(),"APP_KEY", "SECRET_KEY", "com.package.MainActivity" , true, this).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 :
@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 :
@Override protected void onStart() { super.onStart(); Appoxee.onStart(); } @Override protected void onStop() { super.onStop(); Appoxee.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 :
... 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 :
@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(); }
When Integrating Appoxee and choosing not to use an Observer, All Appoxee API Calls will fail unless implementing a thread that will sample the flag
Appoxee.isReady()==true. Only then will the API Calls will execute (Tags,Alias... )
To fully use Appoxee’s Analytics , all of your activities should implement onStart() & onStop in the actvities code :
@Override protected void onStart() { super.onStart(); Appoxee.onStart(); } @Override protected void onStop() { super.onStop(); Appoxee.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)
Advanced Options (Inbox / DeepLink (URLScheme) ) :
If prompted with an error, add this "Import" command to enable Appoxee SDK usage:
import com.appoxee.Appoxee;
Inbox integration - after enabling the Inbox in your Appoxee account (by going to the app's Application Information page and checking Allow Inbox + Rich messages), add the Inbox to your code as follows:
The Inbox feature guarantees your ability to engage the user with rich messages (note that the Inbox cannot be disabled by users, as opposed to Push Notifications) and gives you the option to access features such as Feedback and More Apps . The Inbox must be used in your application's code in order to show it and utilize its features. The InboxMessage activity needs to be added in order to support Push Notifications by Appoxee. Check your Manifest.xml and see that it is added below the Receiver declaration.
Add code that opens the Inbox - the Inbox can be opened from any activity. In the example code below, the Inbox is opened from the main activity layout, using the "openInbox():" function:
public void openInbox(View view) { Intent intent = new Intent(this, Inbox.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); this.startActivity(intent); }
Add a button that opens the Inbox - it is recommended to add a button to open the Inbox. This button is added in the activity layout as follows:
<Button android:id="@+id/open_inbox" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="openInbox" android:text="Open Appoxee Inbox" />
Show the number of unread messages - to show the user the number of unread messages, fetch this number using the following command:
Appoxee.getUnreadMessages();
Deep Link / URL Scheme in Appoxee & Android
Add to your AndroidManifest.xml
<activity android:name="com.appoxee.example.DeepLinkActivity" > <!-- Add the Intent Filter for activity needed to be URLScheme compatible --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="example" android:host="pushnotification" /> </intent-filter> </activity>
Create DeepLinkActivity.java
DeepLink Activity Sample//This sample extends AppoxeeBaseActivity, for onStart() & onStop() integration and analytics public class DeepLinkActivity extends AppoxeeBaseActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); if (intent == null || intent.getData() == null) { finish(); } openDeepLink(intent.getData()); // Finish this activity finish(); } public void openDeepLink(Uri deepLink) { String path = deepLink.getPath(); Utils.Debug("Base path: " + path); //Implement your Code here path = path.replace("/", ""); Intent intent = new Intent(); intent.setClassName(this, path); this.startActivity(intent); } .....
You are now done integrating the Appoxee SDK! Congrats!
1. If you wish to use the SDK Sync API's - press here
2. If you wish to use the SDK Async API's - press here
3. If you wish to use the Custom Push Notification Builder - press here
As mentioned earlier, our Test Application contains a full code sample. it can be downloaded from here.