EN  | 

ES
/Quick Integration Guide /App push notifications /Android

Android integration

Android SDK Quick Guide.

Index

What do you need for integration?

It is important since the project contains the configuration data of your application, that is, the domain where your website is hosted, the safari or iOS certificates or the firebase key that android uses. It all depends on the platforms (web or app) that the project uses.


obtener_AppKey

Integration

This article shows the minimum development that must be done to start registering devices and being able to carry out the first push campaigns.


The Indigitall SDK is compatible with Google messaging services, through the Firebase platform and with the services of HMS or Huawei Mobile Services of Huawei .


You can see it in this tutorial video or read the instructions below:



Adding the SDK dependencies

The first thing to do is open the app / build.gradle file. In the screenshot you can see where to find this app / build.gradle file.

AtenciĆ³n: It is the build.gradle file found in the app folder, NOT the root of the project.


Gradle build file

The library is available through the repository Maven Central . Maven is one of the most used library management tools in Android. To integrate the SDK of indigitall it is necessary to add the following dependencies:


// build.gradle (project)

buildscript {
    repositories {
        ...
        mavenCentral()
        maven {
            url 'https://developer.huawei.com/repo/'
        }
    }
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.huawei.agconnect:agcp:1.2.1.301'
    }
}
allprojects {
    ...
    mavenCentral()
    maven{
        url 'https://developer.huawei.com/repo/'
    }

}


// build.gradle (app)

plugins {
    id 'com.android.application'
    ...
    id 'com.google.gms.google-services'
}
// if you use apply plugin
// apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.huawei.hms:push:4.0.3.301'
    implementation 'com.indigitall:android:4.13.+'
}

Adding the indigitall services

These services are necessary so that our SDK can synchronize device data with indigitall's servers.


<manifest ...>
    <!-- ... -->

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application ...>
        <!-- ... -->

        <!-- MANDATORY -->

        <!-- So that when the user presses a push, the metric is saved -->
        <service android:name="com.indigitall.android.services.StatisticService"/>

        <!-- Daily sync of device data -->
        <service android:name="com.indigitall.android.services.NightService"/>

        <!-- To start services when you restart the device -->
        <receiver android:name="com.indigitall.android.receivers.BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <!-- OPTIONAL -->

        <!-- So that when the user clicks an InApp message, the metric is saved.
        It is only necessary if you use the InApp message functionality -->
        <service android:name="com.indigitall.android.inapp.services.StatisticInAppService" />

        <!-- To obtain the location of the device.
        It is only necessary if you are going to ask for location permission
        to segment pushes by device location -->
        <receiver android:name="com.indigitall.android.receivers.LocationReceiver">
            <intent-filter>
                <action android:name="LocationReceiver.Action.LOCATION_UPDATE" />
            </intent-filter>
        </receiver>

    </application>
</manifest>

Adding Firebase services

Our SDK needs to integrate with your FCM (Firebase Cloud Messaging) project.

FCM makes the connection to the device in order to send it push notifications. This connection is established with the Push Token, an ephemeral token, unique and generated by Google for each device.


<manifest ...>
    <!-- ... -->
    <application ...>
        <!-- ... -->

        <service android:name="com.indigitall.android.services.FirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
        </service>

        <!-- DEPRECATED - NOT ADD
        <service android:name="com.indigitall.android.services.FirebaseInstanceIdService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
        </service>
        -->
    </application>
</manifest>


Adding HMS services

Our SDK needs to integrate with your HMS project (Huawei Mobile Services) to be able to impact the latest Huawei terminals.

HMS makes the connection to the device to be able to send it push notifications. This connection is established with the Push Token, an ephemeral token, unique and generated by HMS for each device.

In order to impact Huawei devices with Harmony, you must perform the following steps:

  1. Add HMSMessagingService service in project manifest.
<manifest ...>
    <!-- ... -->
    <application ...>
        <!-- ... -->

        <service
            android:name="com.indigitall.android.services.HMSMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </applicatio>
</manifest>


  1. Add the Huawei plugin in the gradle of the application, remember that minSdkVersion that Huawei allows is 19:
// build.gradle (app)

plugins {
    id 'com.huawei.agconnect'
}
// if you use apply plugin
// apply plugin: 'com.huawei.agconnect'

android {
    ...

     defaultConfig {
        minSdkVersion 19
     }

     ...
    dependencies {
        ...
        implementation 'com.huawei.hms:push:4.0.3.301'
    }
}

Setting the notifications icon

This icon will be displayed in the top bar of the Android system and in the header of the pushes sent through your app.

It must be a monochrome icon, that is, the image must contain only one color and alpha.

We give you an example with our logo in monochrome:


New tag


Here we show you how your code should be in the AndroidManifest.xml (The icon has to be a png)


<manifest ...>
    <!-- ... -->
    <application ...>
        <!-- ... -->

        <!-- Resource for monochrome icon -->
        <meta-data android:name="indigitall.icon" android:resource="@drawable/YOUR_MONOCHROME_ICON"/>

        <!-- Resource for icon color -->
        <meta-data android:name="indigitall.color" android:resource="@color/colorPrimary"/>
    </application>
</manifest>


* For further clarification on creating icons, we leave you this link to the Android documentation that may help you: Product icons

Initialize the SDK

To initialize the SDK it is necessary to call the init method . This call must occur within the object Activity.

Inside this class, in the onCreate method, we must add the following lines of code:


Indigitall.init(this, "<your_indigitall_app_key>", "<your_firebase_sender_id")



Validate the integration

To verify that the integration was successful, do the following:


  1. From Android Studio, go to the Logcat tab and look for the call PUT / device containing the parameters appKey, deviceId and pushToken and that returns HTTP 200.




  1. Send a notification from the indigitall console. It is possible that the device counter appears at 0 in the console. Don't worry, it may take a few minutes to update, but you don't have to wait, the push should still arrive.



Resources