Integrate the Android SDK
Use the Xtremepush SDK to integrate your Android app in the platform
- In your Application.java file import the library:
import ie.imobile.extremepush.PushConnector;
- In the onCreate method of your Application.java file you must add the following:
public class YOUR_APPLICATION extends Application {
public void onCreate() {
super.onCreate();
...
new PushConnector.Builder("XPUSH_APP_KEY", "GOOGLE_SENDER_ID")
.create(this);
}
public class YOUR_APPLICATION extends Application {
public void onCreate() {
super.onCreate();
...
PushConnector.Builder("XPUSH_APP_KEY", "GOOGLE_SENDER_ID")
.create(this);
}
The command to initialise the PushConnector takes the parameter values in String format. XPUSH_APP_KEY is the SDK key provided when adding the app to the platform. GOOGLE_SENDER_ID is found as part of the steps in setting up Android Push Notifications. The sender ID can also be omitted if not using push notifications.
- In case your Xtremepush project is provisioned in US region add the following code when initialising the PushConnector before the call to
.create(this)
:
.setServerUrl("https://sdk.us.xtremepush.com")
- Finally, in each of your Activities, include a reference to our PushConnector object:
import static ie.imobile.extremepush.PushConnector.mPushConnector;
Make sure you set the user ID
It is recommended that at this stage you use our SDK method to set user IDs by following our dedicated guide to ensure devices can be associated and targeted in your campaigns by your own unique identifier.
Orientation
If you are manually handling orientation changes and you are overriding the OnConfigurationChanged
method, you will also need to add another PushConnector callback to each activity that overrides the OnConfigurationChanged
method.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mPushConnector.onRotation(this);
}
Configuring Proguard
If you are using proguard on your app to minify, optimise, obfuscate etc. then you can add the following settings to your config file to ensure that Xtremepush continues to operate as expected:
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Application classes that will be serialized/deserialized over Gson
#-keep class com.google.gson.examples.android.model.** { *; }
-keep class ie.imobile.extremepush.api.model.** { *; }
# Recommended settings for other dependencies
-keep class com.loopj.android.** { *; }
-keep interface com.loopj.android.** { *; }
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
# Required for inapp and inbox functionality
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
# Required for inbox functionality
-keepattributes JavascriptInterface
-keep public class ie.imobile.extremepush.ui.InboxActivity$InboxInterface
-keep public class * implements ie.imobile.extremepush.ui.InboxActivity$InboxInterface
-keepclassmembers class ie.imobile.extremepush.ui.InboxActivity$InboxInterface {
<methods>;
}
# Required if building your app with Android 23 or lower
-dontwarn ie.imobile.extremepush.ui.PopupDialog
-dontwarn ie.imobile.extremepush.ui.WebViewActivity
Retrieving your Xtremepush ID
If your device is successfully registering with the platform you should be able to retrieve your Xtremepush ID. This can be accomplished by calling the getDeviceInfo()
method on your PushConnector as follows:
mPushConnector.getDeviceInfo()
This method returns a map that contains your devices Cloud Messaging registration ID and its device ID obtained from Xtremepush. If your device has not received an ID then it has not successfully registered and there is an issue with your integration.
If you successfully retrieve the ID it can be used to identify your device on the platform and to send a push notification to just that device.
Debugging
If you are debugging your app, you can turn on the Xtremepush debug logs by adding the following to the PushConnector.builder:
.turnOnDebugLogs(true)
Debug logs can slow down your app and should be turned off before releasing the app.
Excluding certain activities from connecting with Xtremepush
If you are integrating Xtremepush at an application level but would prefer if certain Activities didn't create a PushConnector object (for example, you do not want your splash screen to send the onSessionStartEvent
, you want it to be sent on the Activity following), you can use the following method:
PushConnector.addToExclusionList(ClassName.class.getSimpleName());
Updated 8 months ago