> For the complete documentation index, see [llms.txt](https://documentation.pushly.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.pushly.com/pushly-ja/integration/implementation-steps/android/sdk-kotlin-java.md).

# SDK: Kotlin / Java

## 前提条件

SDKをアプリに統合する前に、以下の要件を満たしている必要があります：

* Google Play ストアサービスがインストールされた、API 19+（Android 4.4）で動作するAndroid端末またはエミュレータ。
* 次を使用するアプリ [<mark style="color:青色;">Jetpack（AndroidX）</mark>](https://developer.android.com/jetpack/androidx/migrate)
* Firebase Sender ID と Server API Key、またはサービスアカウント。まだお持ちでない場合は、以下の手順に従ってください [<mark style="color:青色;">こちらのドキュメント</mark>](/pushly-ja/integration/implementation-steps/android/firebaseapurino.md) それらを生成します。
* SDKキー：Pushlyプラットフォームの `ドメイン設定` ページの `概要` > `詳細` > `ドメイン情報` セクションから取得します。

{% hint style="warning" %}
このガイドでは、あなたがすでに [<mark style="color:青色;">Firebase Messaging を実装している</mark>](https://firebase.google.com/docs/android/setup) こと、また MainApplication クラスをセットアップし、AndroidManifest.xml の `<application>` タグにリンクしていることを前提としています。
{% endhint %}

## ステップ 1: PushSDK フレームワークをインポートする

次を `dependencies` セクションに追加してください。 `app/build.gradle` ファイル:

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

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

{% endtab %}
{% endtabs %}

## ステップ 2: SDK を初期化する

次の `import` をアプリのメインの `Application` クラスに追加してください:

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

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

{% endtab %}

{% tab title="Java" %}

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

{% endtab %}
{% endtabs %}

そして、次の行を `onCreate` メソッド内に追加します。&#x20;

次の `REPLACE_WITH_SDK_KEY` を `setConfiguration` メソッド内で、プラットフォーム設定ページのSDKキーに置き換えてください。

{% 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")
        return@showNativeNotificationPermissionPrompt
    }

    println("権限が付与されました: $granted、応答: $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("権限リクエストでエラーが発生しました: %s", error);
    } else {
        System.out.printf("権限が付与されました: %b、応答: %s", granted, response);
    }

    return null;
});
```

{% endtab %}
{% endtabs %}

## ステップ 3: 実装をテストする

Android デバイスまたはエミュレーターでアプリを実行し（エミュレーターには `Google Play ストア サービス` がインストールされていることを確認）、正しくビルドされることを確認します。

前のステップで追加したコードにより、アプリ起動時にプッシュ権限ダイアログが表示されます。これは [<mark style="color:青色;">SDK メソッド</mark>](/pushly-ja/integration/implementation-steps/android/sdk-kotlin-java/sdkmesoddo.md#manually-triggering-the-permission-dialog) を使用して、ダイアログを表示するタイミングを制御することでカスタマイズできます。

ダイアログを承認した後、プラットフォームにログインして `Notifications > Create Notification` へ移動し、 **ネイティブ: Android** チャネル

## 次のステップ

SDK が正しく動作していることを確認したら、次のような追加のオプション機能を引き続き追加できます:

* [<mark style="color:青色;">通知の開封 / アプリリンク / ディープリンクの処理</mark>](/pushly-ja/integration/implementation-steps/android/sdk-kotlin-java/dpurinku.md)
* [<mark style="color:青色;">購読者のプロフィールに属性を付与する</mark>](/pushly-ja/integration/implementation-steps/android/sdk-kotlin-java/sdkmesoddo.md#adding-attributes-to-a-subscribers-profile)
* [<mark style="color:青色;">購読者がどのコンテンツとやり取りしたかに関する情報を送信する</mark>](/pushly-ja/integration/implementation-steps/android/sdk-kotlin-java/sdkmesoddo.md#activity-tracking-url-screen-visits)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/pushly-ja/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.
