Skip to content

ppgco/android-sdk

Repository files navigation

PushPushGo Android SDK

JitPack
GitHub Workflow Status (master)
GitHub tag (latest)

Requirements

  • minSdkVersion: 21
  • configured GMS or HMS in project app

Preparation

Before proceeding the installlation make sure you have completed the steps listed below:

  1. Connect App with Firebase / Huawei project
  2. (GMS only) From Firebase console download google-services.json and place it in app root folder
  3. Add dependencies based on configuration build you use - Groovy/Kotlin

Groovy DSL

// /app/build.gradle
dependencies {
    // GMS
    implementation platform('com.google.firebase:firebase-bom:33.1.2')
    implementation 'com.google.firebase:firebase-messaging'
    // HMS
    implementation 'com.huawei.agconnect:agconnect-core:1.9.1.303'
    implementation 'com.huawei.hms:push:6.11.0.300'
}

Kotlin DSL

// /libs.versions.toml
[versions]
// GMS
firebaseBom = "33.1.2"
firebaseMessaging = "24.0.0"
googleGmsGoogleServices = "4.4.2"

//HMS
agconnectCore = "1.9.1.303"
hmsPush = "6.11.0.300"

[libraries]
// GMS
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebaseBom" }
firebase-messaging = { group = "com.google.firebase", name = "firebase-messaging", version.ref = "firebaseMessaging" }

// HMS
agconnect-core = { module = "com.huawei.agconnect:agconnect-core", version.ref = "agconnectCore" }
hms-push = { module = "com.huawei.hms:push", version.ref = "hmsPush" }

[plugins]
// GMS
google-gms-google-services = { id = "com.google.gms.google-services", version.ref = "googleGmsGoogleServices" }



// /app/build.gradle.kts
plugins { 
    alias(libs.plugins.google.gms.google.services)
}  

dependencies {
    // GMS
    implementation(platform(libs.firebase.bom))
    implementation(libs.firebase.messaging)
    // HMS
    implementation(libs.agconnect.core)
    implementation(libs.hms.push)
}



// /build.gradle.kts
plugins {
    alias(libs.plugins.google.gms.google.services) apply false
}
  1. Provide GMS / HMS credentials in PushPushGo application (/project/providers)

GMS

  • Go to your Firebase console and navigate to project settings
  • Open Cloud Messaging tab
  • Click Manage Service Accounts
  • Click on your service account email
  • Navigate to KEYS tab
  • Click ADD KEY
  • Click CREATE NEW KEY
  • Pick JSON type and click create
  • Download file and upload it in PushPushGo Application (/project/providers) in FCM v1 credentials section

HMS

  • Go to your Huawei developers console
  • Navigate to your project
  • Open project settings
  • Collect required info (appId, authUrl, pushUrl, appSecret)
  • Provide credentials in PushPushGo Application (/project/providers) in HMS Provider section
  1. In PushPushGo application collect your project ID and generate API KEY in access manager (/user/access-manager/keys) as u will need them later

Instalation

  1. Add SDK dependency to Your project

Groovy DSL

// /build.gradle
allprojects {
    repositories {
    // local repo
    mavenLocal()
    // or
    // jitpack
    maven { url 'https://jitpack.io' }
    }
}


// /app/build.gradle
dependencies {
    // local repo
    implementation 'com.pushpushgo:sdk:<version>'
    // or
    // jitpack
    implementation "com.github.ppgco.android-sdk:sdk:<version>"
}

Kotlin DSL

// /settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven ( "https://jitpack.io" )
    }
}



// /libs.versions.toml
[versions]
ppgSdk = "2.2.2"

[libraries]
ppg-sdk = { module = "com.github.ppgco.android-sdk:sdk", version.ref = "ppgSdk" }



// /app/build.gradle.kts
dependencies {
    implementation(libs.ppg.sdk)
}
  1. Add to Your AndroidManifest.xml:

In application tag: Here you should pass your PPG project id and api key you have generated for that project

<meta-data
	android:name="com.pushpushgo.apikey"
	android:value="{apiKey}" />
<meta-data
	android:name="com.pushpushgo.projectId"
	android:value="{projectId}" />

In your main activity tag:

<activity
    android:launchMode="singleTop"
<intent-filter>
    <action android:name="APP_PUSH_CLICK" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
  1. Add to your MainActivity:

in onCreate():

if (savedInstanceState == null) {
    PushPushGo.getInstance().handleBackgroundNotificationClick(intent);
}

in onNewIntent():

PushPushGo.getInstance().handleBackgroundNotificationClick(intent);
  1. Add to Your Application.onCreate():
PushPushGo.getInstance(this);
  1. Configuration
  • Change default notification color: override @color/pushpushgo_notification_color_default
  • Change default notification channel id: override @string/pushpushgo_notification_default_channel_id
  • Change default notification channel name: override @string/pushpushgo_notification_default_channel_name
  • Change default notification icon: override
    • res/drawable-hdpi/ic_stat_pushpushgo_default
    • res/drawable-mdpi/ic_stat_pushpushgo_default
    • res/drawable-xhdpi/ic_stat_pushpushgo_default
    • res/drawable-xxhdpi/ic_stat_pushpushgo_default

Usage

  • Register subscriber:
PushPushGo.getInstance().registerSubscriber();
  • Unregister:
PushPushGo.getInstance().unregisterSubscriber();
  • Send beacon:
PushPushGo.getInstance().createBeacon()
.set("see_invoice", true)
.setCustomId("SEEI")
.appendTag("demo")
.appendTag("mobile", "platform")
.send();

Publishing

To maven local repository:

$ ./gradlew :library:publishToMavenLocal

Tests

Run tests in library module:

$ ./gradlew :library:testDebug

Generate coverage report:

$ ./gradlew :library:jacocoTestReport

HTML coverage report path: library/build/reports/jacocoTestReport/html/