logo

Android SDK Integration – Quick Start Guide

To include Connecto’s Android SDK in your application, you need to point a dependency on Connecto’s maven repo and include our SDK in your app’s dependencies as follows

Add dependencies to app/build.gradle

repositories {
mavenCentral()
maven { url ‘http://www.connecto.io/maven-repo’ }
}

dependencies {
compile “io.connecto:connecto-android-sdk:0.0.7″
compile “com.google.android.gms:play-services-gcm:3.1+”
}

Connecto requires a minimum 3.1 version of google play services. If you are already using an exact version string, you can leave it as is as long as the version is greater than 3.1.

Add permissions to app/src/main/AndroidManifest.xml:

We will also need some necessary permissions in your AndroidManifest.xml for registering your app and receiving push notifications if not already setup. For setting up the permission, replace the PACKAGE_NAME with your own package name. You need to add these two permissions before the <application> tag.

<permission android:name=“YOUR_PACKAGE_NAME.permission.C2D_MESSAGE” android:protectionLevel=“signature” />
<uses-permission android:name=“YOUR_PACKAGE_NAME.permission.C2D_MESSAGE” />

We also need to have these extra permissions in AndroidManifest.xml file (ignore the ones you may already have). These lines should be used as it is in your file.

<uses-permission android:name=“android.permission.INTERNET” />
<uses-permission android:name=“android.permission.ACCESS_NETWORK_STATE” />
<uses-permission android:name=“android.permission.GET_ACCOUNTS” />
<uses-permission android:name=“com.google.android.c2dm.permission.RECEIVE” />
<uses-permission android:name=“android.permission.WAKE_LOCK” />

Also, we need to inform the OS for allowing a service that should handle the inbound notifications. These lines should go inside the <application> tag.

<receiver android:name=“io.connecto.android.sdk.ConnectoGCMReceiver”
android:permission=“com.google.android.c2dm.permission.SEND” >
  <intent-filter>
    <!– Receives the actual messages. –>
    <action android:name=“com.google.android.c2dm.intent.RECEIVE” />
    <!– Receives the registration id. –>
    <action android:name=“com.google.android.c2dm.intent.REGISTRATION” />
  </intent-filter>
</receiver>

The Google Cloud Messaging will work only for the devices with minimum Android SDK version of 8. If the SDK version is below 8, the device will not be able to receive any communication from GCM. If notifications are necessary for you app, please add these lines to your AndroidManifest.xml:

<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“17” />

Specifying writeKey in res/values/connecto.xml:

Now add the writeKey of your project to be specified in the resources files. In your projects’s res/values/ add a new “Values resource file” with optional name of connecto.xml. You need to add the following lines to connecto.xml.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<resources>
  <!–Required, your Connecto project write key–>
  <string name=“connecto_write_key” >CONNECTO_WRITE_KEY</string>
 <string name=“push_icon”>transparent logo</string>                                                                                <string name=“push_icon_pre_lollipop”>logo</string>
</resources>

You need to replace the CONNECTO_WRITE_KEY with the write key provided to you by Connecto and logo with the name of your logo image. For example, if the name of the logo image you would like to include in push notifications is “logo.png”, you should write here as “logo”. We assume that this file will be available in drawables.

Including Connecto in your activity to receive push notifications:

  • You need to import Connecto in your activity as below:

import io.connecto.android.sdk.Connecto;

  • Next, you need to send us the identify call, otherwise we will not be able to obtain user’s registration Id.

private Connecto connecto = null;
// Get SENDER_ID fom GCM.
String SENDER_ID = “YOUR_SENDER_ID”;

protected void onCreate(Bundle savedInstanceState) {
  connecto = Connecto.with(YourActivity.this);
  connecto.identify(“RandomUser”, new Traits().putValue(“name”, “ABC”))
  //You can also track any event if you want
  connecto.track(“Add to Cart”, new Properties().putValue(“value”, 800));
  connecto.registerWithGCM(YourActivity.this, SENDER_ID);
}

You need to give your Sender ID which you should get from GCM. For identify, the first parameter is the unique ID by which this user should be identified and the second parameter is the Traits object, which is essentially a Map<String, Object>.

 

2 found this helpful