SDK: Kotlin / Java

Prerequisites

Before you can integrate the SDK with your app the following requirements must be met:

  • Android device or emulator running API 19+ (Android 4.4) with Google Play Store Services installed.

  • An app that uses Jetpack (AndroidX)

  • Firebase Sender ID and Server API Key or Service Account. If you do not already have these follow our documentation to generate them.

  • SDK Key: Obtained from the Pushly Platform in the Domain Settings page under the Overview > Details > Domain Information section.

This guide assumes that you have already implemented Firebase Messaging in your application and have also set up a MainApplication class and linked it in your AndroidManifest.xml's <application> tag.

Step 1: Import the PushSDK Framework

Add the following to the dependencies section of your app/build.gradle file:

dependencies {
    ...
    implementation 'com.pushly.android:pushsdk:[1.0, 2.0['
}

Step 2: Initialize the SDK

Add the following import to your app's main Application class:

import com.pushly.android.PushSDK

And then add the following lines inside of the onCreate method.

Replace the REPLACE_WITH_SDK_KEY in the setConfiguration method with the SDK Key from the platform settings page.

PushSDK.logLevel = PNLogLevel.INFO
PushSDK.setConfiguration(appKey="REPLACE_WITH_SDK_KEY", context=this)

PushSDK.PushNotifications.showPermissionPrompt(completion={ granted, response, error ->
    error?.let {
        println("Error encountered in permission request: $error")
        return@showNativeNotificationPermissionPrompt
    }

    println("Permissions granted: $granted, response: $response")
})

Step 3: Test the Implementation

Run your app on an Android device or emulator (ensuring the emulator has Google Play Store Services installed) to make sure it builds correctly.

The code you added in the previous step will show the push permission dialog upon app open. This can be customized by using SDK methods to control when the dialog shows.

After accepting the dialog, log into the platform and navigate to Notifications > Create Notification and send your first notification, targeting the Native: Android channel, to your device.

Next Steps

Once you have confirmed the SDK is working properly you may continue to add additional optional functionality like:

Last updated