Skip to content

Integrate Android SDK (Kotlin / Java)

The Android SDK is required to enable push notifications in your application. It handles device registration with the Push0 API and ensures the device can receive notifications.

When integrated, the SDK automatically registers the device, obtains the push token from the system, and securely sends it to the Push0 backend. This registration step links the device to your application, allowing notifications to be delivered reliably.

Without the SDK, devices cannot register with the Push0 service and will not be able to receive push notifications.

You can use the SDK in both Kotlin and Java applications.

Warning

Google Play Services Plugin is required and your google-services.json file in your app folder

1. Adding Push0 android client SDK to your project

1 - app/build.gradle

add this

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'


android {
    namespace 'your_application_package'
    compileSdk 36
    buildToolsVersion '36.0.0'

    defaultConfig {
        applicationId 'your_application_package'
        minSdk 24 // minSdk 24 is required! Lower SDK levels are not supported!
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11
    }

}

dependencies {

    implementation('com.push0.android.client:1.0.0') // this is Push0 Android Client SDK dependency

    implementation('com.google.android.gms:play-services-base:18.1.0')  // use newest version
    implementation('com.google.firebase:firebase-core:21.1.1')          // use newest version
    implementation('com.google.firebase:firebase-messaging-ktx:23.1.1') // use newest version
}

apply plugin: 'com.google.gms.google-services'

Warning

minSdk 24 is required!
Lower SDK levels are not supported!

Note

Maven Dependency coordinate:
com.push0.android.client:1.0.0


2 - build.gradle

add this to your project

buildscript {
    ext.kotlin_version = '2.2.0' // newest kotlin version
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.13.1'
        classpath 'com.google.gms:google-services:4.4.4' // google-services plugin newest version
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

3 - Paste your google-services.json file to your project app folder.

4 - Sync gradle changes


2. Code

1 - Initialize

Setting your apiKey and appId

package your_application_package

import androidx.multidex.MultiDexApplication
import androidx.multidex.MultiDex
import com.push0.android.client.Push0
import com.push0.android.client.data.model.Push0RemoteMessage
import com.push0.android.client.internal.util.apiClient.data.model.P0NotificationActionButton
import com.push0.android.client.listener.ActionListener


class AppExample : MultiDexApplication() {

    val appId = "my_app_id" // Example: "app_g454h65"
    val apiKey = "my_api_key"

    val logLevel = if(BuildConfig.DEBUG){
       Push0.LogLevel.DEBUG 
    }else {
        Push0.LogLevel.NONE
    }

    override fun onCreate() {
        super.onCreate()

    Push0.setActionListener(object: ActionListener{
        override fun onInitialized() {
            // invoked when Push0 android SDK was initialised!
        }

        override fun onNotificationReceived(message: Push0RemoteMessage) {
            // invoked in case a notification was received
        }

        override fun onNotificationDismissed(message: Push0RemoteMessage) {
            // invoked in case a notification was dismissed
        }

        override fun onNotificationClicked(message: Push0RemoteMessage) {
            // invoked in case a notification was clicked
        }

        override fun onNotificationButtonClicked(
            message: Push0RemoteMessage,
            clickedButton: P0NotificationActionButton
        ) {
           // invoked in case a notification button was clicked
        }
    })

        Push0.initialize(applicationContext, appId, apiKey,null,null,logLevel) // initialisation

    }
}


2 - Enabling developer mode

Warning

Use only in DEBUG mode. For example when BuildConfig.Debug is true There is no option to disable developer mode on current device.

Push0.enableDeveloperMode()


3 - LogLevel

Indicates level of logs.

val logLevel = if(BuildConfig.DEBUG){
   Push0.LogLevel.DEBUG 
}else {
    Push0.LogLevel.NONE
}

Push0.initialize(this, appId, apiKey,null,null,logLevel)

4 - Setting user email or custom id

Indicates level of logs.

val email = "[email protected]"
val customUserId = "my_backend_custom_user_id"

val logLevel = if(BuildConfig.DEBUG){
   Push0.LogLevel.DEBUG 
}else {
    Push0.LogLevel.NONE
}

// Can be set during initialisation:
Push0.initialize(applicationContext, appId, apiKey, customUserId, email, logLevel)

// or anywhere on any screen (email + customUserId at the same time):
Push0.setCustomUserIdAndEmail(customUserId, email)

// or separately on any screen:
Push0.setUserEmail(email)
Push0.setCustomUserId(customUserId)

5 - User tags

Adding or removing device tags

val tag = "my_tag"

// Add
Push0.addDeviceTag(tag)

// Remove
Push0.removeDeviceTag(tag)

6 - Notification small icon

Small icon is your app icon which will be displayed in status bar and many other places.

// Set
Push0.setSmallIcon(R.drawable.ic_stat_my_app_icon)

7 - User logout

Should be used when your user has logged out of your application or there is a need to remove current FCM push token.

Push0.unregister(applicationContext)

Warning

This method unregisters current user device and creates a new one.


8 - Clearing resources

Use when your app is being closed and can clear all resources.

Push0.onCleared()

Warning

This clears current initialisation status and resources.
No SDK method can be used after this !!