(Older Vers 3.5.2) Integrate your App with the Platform

Create an App on the Platform

1. Add your App on the platform by clicking "+ NEW APP" on your xtremepush Dashboard at xtremepush.com

 

 

2. Enter the App Name, upload the App icon, and give a short description of the app. An App key and token have been automatically generated. The App key is used in your Android project to connect the app and platform. The app token will only be used if you use the external API. Save your settings and copy the app key. Your saved settings should be similar to the following.

 

Modify the AndroidManifest.xml

AndroidManifest.xml modifications are required to use the xtremepush Library. Add the following permissions under the manifest tag:

<!-- REQUIRED for xtremepush -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

 <!-- OPTIONAL xtremepush settings-->
 <!-- REQUIRED FOR GEO-LOCATION-->
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <!-- REQUIRED FOR IBEACON -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- REQUIRED IF you support iBeacon and your app must support devices that don't support BLE -->
<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="false" />

Add the following receivers, and activities under the application tag:

Note: Replace any reference to YOUR_PACKAGE_NAME with the package name of your application. Entries that need further modification will have a comment “MODIFICATION NEEDED”

<activity
    android:name="ie.imobile.extremepush.ui.DisplayPushActivity"
    android:label="Push received"
    android:theme="@android:style/Theme.Dialog"
    android:exported="false" />

<activity
    android:name="ie.imobile.extremepush.ui.WebViewActivity"
    android:exported="false" />

<!-- REQUIRED FOR LOCATION SERVICES-->
<service
   android:name="ie.imobile.extremepush.location.ProxymityAlertReceiver"/>

<activity
   android:name="ie.imobile.extremepush.ui.LocationDialogActivity"
   android:label="Locations are not available"
   android:theme="@android:style/Theme.Dialog"
   android:exported="false" />

<!-- REQUIRED FOR GEO LOCATION SERVICES -->
<service android:name="ie.imobile.extremepush.location.GeoLocationService" />
<!-- REQUIRED FOR IBEACON --> <service android:name="ie.imobile.extremepush.beacons.BeaconLocationService" /> <receiver android:name="org.altbeacon.beacon.startup.StartupBroadcastReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.ACTION_POWER_CONNECTED" /> <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /> </intent-filter> </receiver> <service android:enabled="true" android:exported="false" android:isolatedProcess="false" android:label="beacon" android:name="org.altbeacon.beacon.service.BeaconService" /> <service android:name="org.altbeacon.beacon.BeaconIntentProcessor" android:enabled="true" android:exported="false" />


FCM API Key
Google Cloud Messaging is the transport method that xtremepush supports for Android notifications. It is now known as Firebase Cloud Messaging (FCM) if you are enabling notifications then you will need to upload your FCM API Key. Go to your app home and navigate to Settings > Application Keys. On the right hand side select the Android App radio button and upload your app's FCM Application Key. If you have not set up an FCM API Key before this is covered in our article on FCM API Keys (if you have an existing Google Project from pre Sept 2016 you may know this as the GCM API Key and already have one generated).

 

Setting up Cloud Messaging support for your app

Now that you have added your FCM API key to the xtremepush platform you must set up support for messaging in your app.

Modify the AndroidManifest.xml

AndroidManifest.xml modifications are required to use Cloud Messaging. Note: Replace any reference to YOUR_PACKAGE_NAME with the package name of your application. Entries that need further modification will have a comment “MODIFICATION NEEDED”

<!-- REQUIRED PERMISSIONS for GCM -->
<!-- A Google account is not a requirement on devices running Android 4.0.4 or higher so GET_ACCOUNTS may be omitted if you target 4.0.4 and up (https://developer.android.com/google/gcm/client.html) -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- This app has permission to register with GCM and receive message -->
<!-- MODIFICATION NEEDED - Replace YOUR_PACKAGE_NAME with your package name -->
<permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" />
<!-- The two elements above ensure that only this application can receive the messages and registration result -->

Add the following receivers, and activities under the application tag:

<service android:name="ie.imobile.extremepush.GCMIntentService" />

<!-- REQUIRED FOR GCM, LOCATION AND BEACON -->
<receiver
    android:name="ie.imobile.extremepush.receivers.GCMReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <action android:name="ie.imobile.extremepush.BEACON_SERVICE_STARTED" />
        <!-- MODIFICATION NEEDED - Replace YOUR_PACKAGE_NAME with your package name --> 
        <category android:name="YOUR_PACKAGE_NAME" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
        <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
    </intent-filter>
</receiver>

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Setting up Google Play Services

If you have not already done so you should setup Google Play Services. The xtremepush SDK depends on Google Play Services for Cloud Messaging registration as this is now Google’s recommended integration. The library is built against Google Play Services, but does not package it for applications. Instead, any application that wants to support Cloud Messaging needs to include Google Play Services as a dependency. Set up instructions can be found [here](http://developer.android.com/google/play-services/setup.html#Install).


Initialise the SDK in your Application

To enable xtremepush Notifications you will use your app key from the Settings > General Settings section of your app home on xtremepush.com and your project number from the google developer console to connect your app to the platform. If you can't remember where to get this value it is described in the section on generating an FCM API Key (if you have existing Google Projects from pre Sept 2016 you may know this as the GCM API Key) for your project

The following 4 steps should be taken in any Activity that can be active in your application. In an application with a single base activity that updates via fragments you can just add the integration code in your base activity. In applications with multiple independent activities the integration code should be placed in all activities.


1. In your Activity import the library:



import ie.imobile.extremepush.*;


2. Declare a new member variable of type PushConnector in your main activity:



public class MainActivity extends Activity {

private PushConnector mPushConnector;

3. In the onCreate method you must add the following:



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// INITIALISE THE XTREMEPUSH CONNECTOR HERE
mPushConnector = new PushConnector.Builder("XTREME_PUSH_APP_KEY", "GOOGLE_PROJECT_NUMBER")
.create(this);

/* OPTIONAL USAGE -- IF USING LOCATION USE THIS VERSION WITH .setEnableLocations(true)
mPushConnector = new PushConnector.Builder("XTREME_PUSH_APP_KEY", "GOOGLE_PROJECT_NUMBER")
.setEnableLocations(true)
.create(this);
*/


The command to initialise the PushConnector takes the XTREME_PUSH_APP_KEY and the GOOGLE_PROJECT_NUMBER as inputs in String format.

4. Finally add call backs to the xtremepush connector in the onActivityResult, onNewIntent, onStart, onResume, onPause, onStop and onDestroy methods as shown:



 @Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//xtremepush onActivityResult Callback
mPushConnector.onActivityResult(requestCode, resultCode, data);
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//xtremepush onNewIntent Callback
mPushConnector.onNewIntent(intent);
}

@Override
protected void onStart() {
super.onStart();
//xtremepush onStart Callback
mPushConnector.onStart(this);
}

@Override
protected void onResume() {
super.onResume();
//xtremepush onResume Callback
mPushConnector.onResume(this);
}

@Override
protected void onPause() {
super.onPause();
//xtremepush onPause Callback
mPushConnector.onPause(this);
}

@Override
protected void onStop() {
super.onStop();
//xtremepush onStop Callback
mPushConnector.onStop(this);
}

@Override
protected void onDestroy() {
super.onDestroy();
//xtremepush onDestroy Callback
mPushConnector.onDestroy(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 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>;
}

 

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 it's device id obtained from XtremePush server. 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.

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.