Add Appoxee SDK to Android Studio
Android SDK V4.0.0 AAR file which can be downloaded from our download page.
Android Example App V4.0.0 located in the download page contains a full code sample of what is written here.
1. Download the Android SDK V4.0.0 AAR file from the download page.
2. Open the Android Studio and create your application, with minSdkVersion 16.
3. Import the Appoxee SDK aar file, click on File->New->New Module
4. Select "Import .JAR/.AAR Package", click Next
5. Select the Appoxee SDK aar file from the location you have saved it, click Next
6. Add New added Module Dependency
Go to File->Project Structure->app dependencies
7. Click on + button and choose Module dependency
8. Choose your added module, click OK
9. Gradle project sync start, if it not start, you can sync it using Sync button.
10. Make sure your application build.gradle file include the applicationId attribute for android defaultConfig. Alternately, you can replace ${applicationId} with you application package (e.g com.yourapppackage.app). Also please add the following dependencies to your app's gradle.build dependencies section :
app build.gradle
android {
...
defaultConfig {
applicationId "com.yourapppackage.app" //make sure you have this
...
}
}
dependencies {
compile 'com.google.android.gms:play-services-gcm:9.2.0' // 9.2.0 or above
compile 'com.google.code.gson:gson:2.6.2' //2.6.2 or above
compile 'com.google.dagger:dagger:2.11' //use same version 2.11
compile project(':appoxee_sdk_4.0.0')
}
. This document explains how to add the Appoxee code to your application code
Source code integration
1. In the Application class of your android project, add following code
Code Block | ||||
---|---|---|---|---|
| ||||
public class AppoxeeTestApp extends Application {
...
@Override
public void onCreate() {
super.onCreate();
...
AppoxeeOptions opt = new AppoxeeOptions();
opt.sdkKey = SDK_KEY;
opt.googleProjectId = GOOGLE_PROJECT_ID;
Appoxee.engage(this, opt);
...
}
...
} |
pass your SDK Key and google project Id, SDK key is present in your Appoxee Application dashboard. Add application in Android manifest file.
Code Block | ||||
---|---|---|---|---|
| ||||
public class MyPushBroadcastReceiver extends PushDataReceiver {
@Override
public void onPushReceived(PushData pushData) {
Log.d("APX", "Push received " + pushData);
}
@Override
public void onPushOpened(PushData pushData) {
Log.d("APX", "Push opened " + pushData);
}
@Override
public void onPushDismissed(PushData pushData) {
Log.d("APX", "Push dismissed " + pushData);
}
} |
3. For Custom layout Notifications, add this code in Application class, before calling Appoxee.engage method
Code Block | ||||
---|---|---|---|---|
| ||||
//add this only for the custom layout notifications
CustomXmlLayoutNotificationCreator.Builder builder = new CustomXmlLayoutNotificationCreator.Builder(this);
builder.setLayoutResource(R.layout.custom_notification_layout) //your custom notification layout
.setIconResourceId(R.id.appoxee_default_push_icon)
.setTextResourceId(R.id.appoxee_default_push_message)
.setTitleResourceId(R.id.appoxee_default_push_subject)
.setTimeResourceId(R.id.appoxee_default_push_hour);
opt.customNotificationCreator = new CustomXmlLayoutNotificationCreator(builder);
Appoxee.engage(this, opt); |
4. If prompted with an error, add this "Import" command to enable Appoxee SDK usage:
Code Block | ||
---|---|---|
| ||
import com.appoxee.Appoxee; |
5. Add a callback to appoxee finished all initialization, the callback will be called when Appoxee is up and ready, or if server hand-shaking is failed.
Code Block | ||||
---|---|---|---|---|
| ||||
Appoxee.instance().addInitListener(new Appoxee.OnInitCompletedListener() {
@Override
public void onInitCompleted(boolean successful, Exception failReason) {
}
});
|
6. Another way to check the initialization finish or not is to use following method:
Code Block | ||
---|---|---|
| ||
Appoxee.instance().isReady(); |
return true when appoxee has finished launching.
Advanced Options (Deep-linking)
Deep Link / URL Scheme in Appoxee & Android, add following code in the manifest file, if you wants to open any other activity from push notification click.
Code Block | ||||
---|---|---|---|---|
| ||||
<activity android:name="com.appoxee.example.AnyActivity" >
<!-- 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" />
<!-- Accepts URIs that begin with "example://pushnotification" -->
<data android:scheme="example"
android:host="pushnotification" />
</intent-filter>
</activity> |