Firebase SDK Setup

Requirements

  • Google Firebase App Configuration
  • Android Studio
  • Android Device or Emulator
  • D·engage Mobil SDK for Android supports version 4.4 (API Level 19) and later.
  • D·engage Mobil SDK for Huawei supports all new versions.

D·engage Android SDK provides an interface which handles push notification messages easily. Optionally, It also gives to send event functionality such as open and subscription to D·engage Platform.

dengage.android.sdk latest version 4.1.8

Supports Android API level 4.1.x or higher.

1. Create Firebase App

1.1 Create an Android app on Firebase Console.

1.2 Download your configuration file (google-services.json) and copy the file on your app directory.

1.3 Add the following dependencies to project >build.gradle file and project > settings.gradle which is located in your project root directory and sync.

buildscript {  
        repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' } // ANDROID Maven repository (Add this line)
        maven { url 'https://developer.huawei.com/repo/'} // HUAWEI Maven repository (Add this line)
    }  
        dependencies {  
            classpath "com.android.tools.build:gradle:7.0.2"  
						
						classpath 'com.google.gms:google-services:4.3.10'// Add this line
						classpath 'com.huawei.agconnect:agcp:1.4.1.300'// Add this line
					}
}

// Valid in old android studio app.
allprojects {  
   repositories {
        mavenCentral()
				maven { url 'https://jitpack.io' } // add this line
				maven { url 'https://developer.huawei.com/repo/' } // HUAWEI Maven repository

    }
}

// Valid in old android studio app.
apply plugin: 'com.google.gms.google-services' // Add this line, Please apply google-services plugin at the bottom of the build file.  

1.4 Add the following dependencies to app > build.gradle file which is located in your project app directory and sync.

// Valid in new android studio app.
plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'com.huawei.agconnect'
}

// Valid in old android studio app.
apply plugin: 'com.android.application'

dependencies {  
	
    // dengage
    implementation 'com.github.whitehorse-technology:dengage.android.sdk:4.1.4'//Add this line

    // firebase
    implementation 'com.google.firebase:firebase-core:19.0.1'//Add this line
    implementation "com.google.firebase:firebase-messaging:22.0.0"//Add this line
    implementation 'com.google.firebase:firebase-analytics:19.0.1'//Add this line
			
    // huawei
    implementation 'com.huawei.hms:push:5.3.0.304'//Add this line
    implementation 'com.huawei.hms:ads-identifier:3.4.30.307'//Add this line			 
		// gson
    implementation 'com.google.code.gson:gson:2.8.7'//Add this line

1.5 For android sdk minSdkVersion should be 19 and targetSdkVersion should be 30. (app > build.gradle)

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        minSdkVersion 19 // Update this line
        targetSdkVersion 30 // Update this line
        versionCode 1
        versionName "4.1.4"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        //applicationId "com.dengage.sdk" // Update this line
    }

1.6 Run your app and verify your configuration.

2. Configuration

2.1 If you prefer to handle messages by D·engage, paste the following config values into your AndroidManifest.xml file. Thus all incoming push messages that received from D·engage Platform will be generated by the SDK.

<application ...>
...
<!-- Fcm Messaging Service for handling push messages comes from firebase -->
<service
    android:name="com.dengage.sdk.FcmMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
<!-- Hms Messaging Service for handling push messages comes from huawei messaging service -->
<service
    android:name="com.dengage.sdk.HmsMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
    </intent-filter>
</service>
<!-- For handling push notifications comes to messaging service classes -->
<receiver android:name="com.dengage.sdk.NotificationReceiver"
    android:exported="false">
    <intent-filter>
      <action android:name="com.dengage.push.intent.RECEIVE" />
      <action android:name="com.dengage.push.intent.OPEN" />
      <action android:name="com.dengage.push.intent.DELETE" />
      <action android:name="com.dengage.push.intent.ACTION_CLICK" />
      <action android:name="com.dengage.push.intent.ITEM_CLICK" />
      <action android:name="com.dengage.push.intent.CAROUSEL_ITEM_CLICK" />
    </intent-filter>
</receiver>
...
</application>

2.2 Make sure that your app has the following permissions.

<manifest ...>  
...
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
...
</manifest>

3. Defining Push Application

3.1 Login your D·engage Panel. Navigate “Settings>Push Applications” page and click the “Add > Android (Google) Application” button.

3.2 Visit your project settings page on Firebase Console and navigate to Cloud Messaging page. Copy your Server Key and Sender ID

3.3 Paste your Server Key and Sender ID on your D·engage android app settings page.

3.4 You’ll see an Integration Key which is automatically generated. Keep the key for next steps.