# 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 [<mark style="color:blue;">Jetpack (AndroidX)</mark>](https://developer.android.com/jetpack/androidx/migrate)
* Firebase Sender ID and Server API Key or Service Account. If you do not already have these follow [<mark style="color:blue;">our documentation</mark>](/integration/implementation-steps/android/firebase-app-setup.md) to generate them.
* SDK Key: Obtained from the Pushly Platform in the `Domain Settings` page under the `Overview` > `Details` > `Domain Information` section.

{% hint style="warning" %}
This guide assumes that you have already [<mark style="color:blue;">implemented Firebase Messaging</mark>](https://firebase.google.com/docs/android/setup) in your application and have also set up a MainApplication class and linked it in your `AndroidManifest.xml's <application>` tag.
{% endhint %}

## Step 1: Import the PushSDK Framework

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

{% tabs %}
{% tab title="app/build.gradle" %}

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

{% endtab %}
{% endtabs %}

## Step 2: Initialize the SDK

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

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
import com.pushly.android.PushSDK
```

{% endtab %}

{% tab title="Java" %}

```java
import com.pushly.android.PushSDK;
```

{% endtab %}
{% endtabs %}

And then add the following lines inside of the `onCreate` method.&#x20;

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

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
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")
})
```

{% endtab %}

{% tab title="Java" %}

```java
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;
});
```

{% endtab %}
{% endtabs %}

## 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 [<mark style="color:blue;">SDK methods</mark>](/integration/implementation-steps/android/sdk-kotlin-java/sdk-methods.md#manually-triggering-the-permission-dialog) 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:

* [<mark style="color:blue;">Handling notification opens / app links / deep linking</mark>](/integration/implementation-steps/android/sdk-kotlin-java/deep-linking.md)
* [<mark style="color:blue;">Attaching attributes to a subscriber's profile</mark>](/integration/implementation-steps/android/sdk-kotlin-java/sdk-methods.md#adding-attributes-to-a-subscribers-profile)
* [<mark style="color:blue;">Sending information about what content a subscriber interacts with</mark>](/integration/implementation-steps/android/sdk-kotlin-java/sdk-methods.md#activity-tracking-url-screen-visits)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.pushly.com/integration/implementation-steps/android/sdk-kotlin-java.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
