Push.Express Documentation
  • Push.Express Documentation
  • Quckstart
    • How to use
    • Analytics
    • Demo apps
  • SDK
    • PWA
    • Kotlin
    • Swift
    • Unity
    • Flutter
    • Onesignal
  • API
    • Applications
    • App Instances (Devices)
    • Pushes
    • One-time sending in future
    • Smart weekly sending
    • Instant sending
  • SDK API
    • SDK API specs
Powered by GitBook
On this page
  • PushExpress -- SDK Kotlin
  • Setup Firebase
  • Setup Push.Express
  • Add sdk in your application
  • Obfuscation
  1. SDK

Kotlin

PreviousPWANextSwift

Last updated 28 days ago

PushExpress -- SDK Kotlin

Note: if you need fully unique apps, do , else do all steps below.

You will need to integrate your Push.Express account with Firebase.

  1. Follow

Setup Firebase

  1. Go to and create a new project (or use existing one)

    You can use one project for all your apps.

  2. Open Project Settings -> General

  3. Create new Android app or just download google-services.json from existing app

If you need to create new app, just:

  • Register it

  • Download google-services.json

  • Press next-next-next =)

  1. Put google-services.json to your app dir (like <project>/app/google-services.json)

  2. Add the plugin as a dependency to your project-level build.gradle.kts file: Root-level (project-level) Gradle file (/build.gradle.kts)::

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    plugins {
        alias(libs.plugins.android.application) apply false
        alias(libs.plugins.kotlin.android) apply false
        alias(libs.plugins.kotlin.compose) apply false
        // Add the dependency for the Google services Gradle plugin
        id("com.google.gms.google-services") version "4.4.2" apply false
    }
  3. In your module (app-level) Gradle file (<project>/<app-module>/build.gradle.kts), add the Firebase Cloud Messaging dependency:

    plugins {
        alias(libs.plugins.android.application)
        alias(libs.plugins.kotlin.android)
        alias(libs.plugins.kotlin.compose)
    }
    
    dependencies {
        // Import the Firebase BoM
        implementation(platform("com.google.firebase:firebase-bom:33.7.0"))
    
        // ...
    }

Setup Push.Express

Get Firebase Private key

  1. You can use one project for all your apps.

  2. Open Project Settings

  3. Go to Service accounts, press Generate new private key and save it to file private-key.json (you can use same key for all apps)

Integrate your Push.Express App with Firebase

  1. Open existing App settings or create a new App

  2. Switch type application Android

  3. Paste private-key.json file to Firebase Admin SDK private key textbox

Add sdk in your application

Add the JitPack repository to your build file

Ensure you have the latest Android Studio and Android Gradle Plugin!

// settings.gradle (Project Settings) in Android Studio
// ...
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        // ...
         maven {
            url = uri("https://jitpack.io")
        }
    }
}
Alternatively, if you use old `allprojects` style

In your root-level (project-level) Gradle file (<project>/build.gradle), add the Jitpack repo to repositories list:

// build.gradle (Project: My_Application) in Android Studio
// ...
allprojects {
    repositories {
        // ...
        maven { url "https://jitpack.io" }
    }
}

Add Push.Express SDK dependency

In your module (app-level) Gradle file (<project>/<app-module>/build.gradle), add the pushexpress-android-sdk dependency:

// build.gradle (Module :app) in Android Studio
// ...
dependencies {
    // ...
     implementation ("com.github.pushexpress:pushexpress-android-sdk:1.2.0")
}

Add required code

  1. Add code to your Android Studio app

    import com.pushexpress.sdk.main.SdkPushExpress
    
    const val PUSHEXPRESS_APP_ID = "####-######"
    
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            SdkPushExpress.initialize(PUSHEXPRESS_APP_ID)
            SdkPushExpress.setExternalId("<some_external_id>") // optional
            SdkPushExpress.activate() // Don't forget to activate SDK workflow!
    
            Log.d("Myapp", "App Instance Token: " +
                    SdkPushExpress.getInstanceToken())
            Log.d("Myapp", "App External ID: " +
                    SdkPushExpress.getExternalId())
        }
    }
  2. Ask for notification permissions

    // ...
    import android.content.pm.PackageManager
    import android.os.Build
    import android.widget.Toast
    import androidx.activity.result.contract.ActivityResultContracts
    import androidx.core.content.ContextCompat
    
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            // ...
            askNotificationPermission()
        }
    
        private val notificationPermissionLauncher = registerForActivityResult(
            ActivityResultContracts.RequestPermission()
        ) { isGranted: Boolean ->
            if (isGranted) {
                Toast.makeText(this, "Notifications permission granted", Toast.LENGTH_SHORT)
                    .show()
            } else {
                Toast.makeText(
                    this,
                    "FCM can't post notifications without POST_NOTIFICATIONS permission",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    
        private fun askNotificationPermission() {
            // This is only necessary for API Level > 33 (TIRAMISU)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                if (ContextCompat.checkSelfPermission(this,
                        android.Manifest.permission.POST_NOTIFICATIONS) ==
                    PackageManager.PERMISSION_GRANTED
                ) {
                    // FCM SDK (and your app) can post notifications.
                } else {
                    // Directly ask for the permission
                    notificationPermissionLauncher.launch(
                        android.Manifest.permission.POST_NOTIFICATIONS)
                }
            }
        }
    }

Obfuscation

You can obfuscate your app with standard minifyEnabled true, but if you want more uniq app code, follow the guide below =)

Step 1. Prerequisites

You will need to integrate your Push.Express account with Firebase.

  1. Create or use existing app in Android Studio

Step 2. Download full SDK repo

  1. Unzip and rename directory to pushexpress-android-sdk

  2. Place pushexpress-android-sdk near your app dir, for example

./
  \- MyApplication
  \- pushexpress-android-sdk

Step 3. Obfuscate SDK locally

You need Linux (Ubuntu) or MacOS, it will not work on Windows out of the box!

Open Terminal app and do next steps.

  1. Ensure you have installed Perl, coreutils find and xargs commands

    which perl && which find && which xargs && echo "OK"
  2. In local SDK dir (pushexpress-android-sdk) run obfs.pl script

    cd pushexpress-android-sdk
    ./scripts/obfs.pl
  3. Get new SDK package name, use it in next steps instead of 'com.sdk.pushexpress'

You need to do this step for each app, so you need to have separate local SDK copy for each app!

But you don't need (and it is really bad) to repeat this step if you just want to update your app.

Step 4. Add local SDK dependency

  1. In your settings.gradle add path to local SDK

    // settings.gradle (Project Settings) in Android Studio
    
    include ':sdkpushexpress'
    project(':sdkpushexpress').projectDir = new File('../pushexpress-android-sdk/sdkpushexpress')
  2. In your module (app-level) Gradle file (<project>/<app-module>/build.gradle), add the SDK dependency

    // build.gradle (Module :app) in Android Studio
    
    dependencies {
        ...
        implementation project (":sdkpushexpress")
    }
  3. Run File->Sync Project with Gradle files in Android Studio

Step 5. Add required code

Step 6. Enable project obfuscation

  1. Enable R8.fullMode in your gradle.properties

    # Project-wide Gradle settings
    ...
    android.enableR8.fullMode=true
  2. In your module (app-level) Gradle file (<project>/<app-module>/build.gradle), enable obfuscation (minifyEnabled true)

    // build.gradle (Module :app) in Android Studio
    android {
        ...
        buildTypes {
            release {
                minifyEnabled true
        ...

Step 7. Build and try to send push

  1. Select Release build variants for your app and SDK (don't forget to sign you app)

  2. Build->Clean Project

  3. Build->Build bundle(s) / APK(s)->Build APK(s)

  4. cd ./MyApplication/app/build/outputs/apk/release/
    jadx app-release.apk
    
    grep -ril 'pushexpress' app-release/
    find app-release/ -iname '*pushexpress*'
    
    # you should see no files here

Now you can try to send push in you local device or emulator, make sure all works as expected.

Step 5. Build and try to send push

Full official instructions can be found in .

Go to and create a new project (or use existing one)

Go to your account

Before proceeding with the integration, make sure you have already installed the Firebase SDK in your application. If not, follow steps 4-6 in the

In your settings.gradle.kts, add the Jitpack repo to repositories list (only if you use Gradle feature, default for new projects since Android Studio Electric Eel):

Get your PUSHEXPRESS_APP_ID from account page

Follow

Follow

Download

See

Check obfuscation with decompiler, for example,

Use to learn how to view app installs on your devices and send notifications.

Firebase Cloud Messaging Android guide
Firebase Console
Push.Express
Centralized Repository Declaration
Push.Express
pushexpress-android-sdk.zip
jadx
Push.Express Documentation
Firebase Cloud Messaging integration guide
Push.Express integration guide
Firebase Cloud Messaging integration guide
How to use Push.Express SDK in your Android Studio project
Firebase Console
obfuscation guide
Firebase Cloud Messaging integration guide
Create application in Push.Express
Add sdk in your application