# 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>](https://documentation.pushly.com/integration/implementation-steps/android/firebase-app-setup) 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>](https://documentation.pushly.com/integration/implementation-steps/android/sdk-methods#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>](https://documentation.pushly.com/integration/implementation-steps/android/sdk-kotlin-java/deep-linking)
* [<mark style="color:blue;">Attaching attributes to a subscriber's profile</mark>](https://documentation.pushly.com/integration/implementation-steps/android/sdk-methods#adding-attributes-to-a-subscribers-profile)
* [<mark style="color:blue;">Sending information about what content a subscriber interacts with</mark>](https://documentation.pushly.com/integration/implementation-steps/android/sdk-methods#activity-tracking-url-screen-visits)
