LogoLogo
  • Home
  • Integration & SDKs
    • Web / Browser Push
      • Wordpress Integration Steps
      • Wix Integration Steps
      • Safari
        • Safari on Desktop
        • Safari on Mobile (iOS / iPadOS)
      • SDK
        • SDK Methods
        • SDK Events
        • Customizing Prompt CSS
        • AMP Support
        • E-Commerce / Abandoned Cart
    • Native App Push
      • Apple / iOS
        • P8 Key or P12 Cert Setup
        • SDK: Swift / Obj-C
          • Activity Tracking
          • Deep Linking
          • Live Activities
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Delegates
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • iOS SDK Changelog
      • Android
        • Firebase App Setup
        • SDK: Kotlin / Java
          • Deep Linking
          • Activity Tracking
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Callbacks
          • Live Activities
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • Android SDK Changelog
      • React Native
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: React Native
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
      • Flutter
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: Flutter
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
  • API
    • API Access Management
    • API Reference
  • Platform
    • Dashboard
    • Notifications
      • A/B Testing
      • Custom Buttons
      • Notification Previews
      • Inline Segmentation
      • Notification Templates
      • Macros
      • Native App Push Notifications
    • App Messages
    • Segments
      • Custom Geo Segmentation
    • Campaigns
    • Insights
    • User Management
    • Organizations
      • Multi-Factor Authentication
      • Single Sign On
        • Google Workspace
        • Microsoft Azure AD
        • Okta Workforce
      • Multi-Domain Notifications
      • Multi-Domain Segments
      • API Access
    • Multi-Channel Notifications
  • Info Center
    • Launch Guide & Best Practices
      • Landing Domain Whitelist
    • Web / Browser Push
      • Common Questions
      • Browser Support
      • Retrieve Push User ID
      • Not Getting Prompted
      • Not Receiving Notifications
      • How to Unsubscribe
    • Native App Push
      • Retrieve Push User ID
    • Workflow Planning
Powered by GitBook
On this page
  • Prerequisites
  • Step 1: Import the PushSDK Framework
  • Step 2: Initialize the SDK
  • Step 3: Test the Implementation
  • Next Steps
  1. Integration & SDKs
  2. Native App Push
  3. Android

SDK: Kotlin / Java

PreviousFirebase App SetupNextDeep Linking

Last updated 9 months ago

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

  • Firebase Sender ID and Server API Key or Service Account. If you do not already have these follow 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 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
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")
})
PushSDK.setLogLevel(PNLogLevel.INFO);
PushSDK.setConfiguration("REPLACE_WITH_SDK_KEY", this);

PushSDK.PushNotifications.showPermissionPrompt((granted, response, error) -> {
    if (error != null) {
        System.out.printf("Error encountered in permission request: %s", error);
    } else {
        System.out.printf("Permissions granted: %b, response: %s", granted, response);
    }

    return null;
});

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.

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:

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

Jetpack (AndroidX)
our documentation
implemented Firebase Messaging
Handling notification opens / app links / deep linking
SDK methods
Attaching attributes to a subscriber's profile
Sending information about what content a subscriber interacts with