Android

Adding the SDK dependencies

If you are with a version of Kotlin less than 1.5.21, you will have to add the following implementation of coroutines in the gradle dependencies:

dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    ...

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
}
  • SDK compatibility with Android is as of Android 5.0

Adding 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" />

    <!-- To obtain the location of the device -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
    <application ...>
        <!-- ... -->

        <!-- MANDATORY -->
         <activity android:configChanges="orientation|keyboardHidden" android:excludeFromRecents="true" android:name="com.indigitall.cordova.views.CordovaIndigitallHiddenActivity" android:taskAffinity="" />
        <!-- So that when the user presses a push, the metric is saved -->
        <service android:name="com.indigitall.android.push.services.StatisticService"/>

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

        <!-- To start services when you restart the device -->
        <receiver android:name="com.indigitall.android.push.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.push.receivers.LocationReceiver">
            <intent-filter>
                <action android:name="LocationReceiver.Action.LOCATION_UPDATE" />
            </intent-filter>
        </receiver>

    </application>
</manifest>

Push permission after Android 13 (Api level 33 - Tiramisu)

Android 13 requires you to add the android.permission.POST_NOTIFICATIONS flag to the manifest:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

and also override onRequestPermissionsResult in the Main Activity:

MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  for (String permission : permissions) {
    if (Manifest.permission.POST_NOTIFICATIONS.equals(permission)) {
      Indigitall.INSTANCE.onRequestPermissionsResult(this, Constants.REQUEST_PERMISSION_CODE, permissions, grantResults);
    }
  }
}

Adding Firebase Services

    1. To start you need a file called google-services.json. This file can be exported from the Firebase console.
    1. Move it to the root folder of your project. You should have something like this:

    1. Add the following code in the config.xml file inside the android section.
<platform name="android">
    <resource-file src="google-services.json" target="/google-services.json" />
    ...
</platform>
  1. Once the android project is created, it must be added in the manifest of the application, which can be found in the following path:

  1. Add the following lines:
<service android:exported="false" android:name="com.indigitall.android.push.services.FirebaseMessagingService" >
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
  1. You also have to edit the build.gradle of the application, which can be found in the following path:

  1. Add the following lines:
  • Huawei libraries only have to be added if HMS services is implemented
apply plugin: 'com.huawei.agconnect' 

//gradle project
buildscript {
    repositories {
        ...
       maven {url 'https://developer.huawei.com/repo/'} 
    }
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.0.+' 
    }
}

allprojects {
    repositories {
        ...
        //maven {url 'https://developer.huawei.com/repo/'} 
    }
}
...
//gradle app
apply plugin: 'com.google.gms.google-services'
dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation "com.google.firebase:firebase-core:17.2.2"
    implementation "com.google.firebase:firebase-messaging:22.0.0"
    ...
    // SUB-PROJECT DEPENDENCIES END
}
  1. Gradle 7.0 or later

To find out what version of gradle you have configured in your project go to File->Project Structure->Project under Gradle Version.
Compatibility with the Gradle JDK changes with this version, in this case you must use version 11. To do this, go to the Android Studio->Build, Execution, Deplyment->Build Tools->Gradle menu and select Gradle JDK version 11.
The settings that were in allprojects->repositories have been moved to the settings.gradle file. So you have to modify the gradle of the project and the settings.gradle being as follows:

```groovy
// build.gradle (project)
build script {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.android.tools.build:gradle:4.0.1'
    }
}
//no repository field

```
//settings.gradle
plugin management {
 
    repositories {
        gradlePluginPortal()
        google() //if necessary
        mavenCentral()
    }
}
dependency resolution management {
    ...
    repositories {
        google() //if necessary
        mavenCentral()
    }
}

Adding HMS Services

🚧

WARNING

Currently, in version 2.14.0 of our SDK, HMS services have been excluded because Google prevents any apps with HMS dependencies from being deployed to the PlayStore. As soon as HMS finds a fix, we'll re-publish, and independently, so it doesn't affect this again in the future.

New version 2.16.0 has been released with HMS included and solved this problem with push HMS library version: implementation("com.huawei.hms:push:6.3.0.304")

  1. To start you need a file called agconnect-services.json. This file can be exported from the Huawei developer console .

  2. Move it to the root folder of your project. You should have something like this:

  1. Add the following code in the config.xml file inside the android section.
<platform name="android">
    <resource-file src="agconnect-services.json" target="/agconnect-services.json" />

    ...
</platform>
  1. Once the android project is created, it must be added in the manifest of the application, which can be found in the following path:

  1. Add the following lines:
<service android:exported="false" android:name="com.indigitall.android.hms.services.HMSMessagingService">
    <intent-filter>
        <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
    </intent-filter>
</service>
  1. You also have to edit the build.gradle of the application, which can be found in the following path:

  1. Add the following lines:
apply plugin: 'com.huawei.agconnect' 

buildscript {
    repositories {
        ...
        maven {url 'https://developer.huawei.com/repo/'} 
    }
    dependencies {
        ...
        classpath 'com.huawei.agconnect:agcp:1.7.3.300' 
    }
}

allprojects {
    repositories {
        ...
        maven {url 'https://developer.huawei.com/repo/'} 
    }
}
...
dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    ...
    implementation "com.huawei.hms:push:6.7.0.300"
    // SUB-PROJECT DEPENDENCIES END
}
  1. As of Gradle 7.0 or later, the settings in allprojects->repositories have been moved to the settings.gradle file as follows:
dependencyResolutionManagement {
    ...
    repositories {
        google()
        jcenter() 
        maven {url 'https://developer.huawei.com/repo/'}
    }
}

Exclude HMS Services

If you want to perform the integration without impacting Huawei devices, you have to remove the dependencies from the previous section and add the following code in the application's gradle, where indigitall implementation is:

implementation('com.indigitall:android:5.1.+'){
   exclude group : 'com.indigitall', module:'android-hms'
}
implementation("com.indigitall:android:5.1.+") {
   exclude(group = "com.indigitall", module = "android-hms")
}

Proguard Configuration

Applications that use ProGuard should include the following line in their ProGuard file to ensure proper library functionality:

-keepnames class com.indigitall.android.** { *; }

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:

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