> 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/dpurinku.md).

# ディープリンク

SDKがディープリンクを処理する方法と、アプリ内でカスタムナビゲーションを行う方法の概要

PushSDK は次の方法で通知の開封を処理します:

* デフォルトでは、SDK は新しい `ACTION_VIEW` インテントを、通知に添付されたランディング URL を使用して自動的に作成します。
* 次を実装すると `onPushSDKDidReceiveNotificationDestination` ライフサイクルコールバックを使って、通知が開かれたときに必要な任意のカスタム処理を実行できます。

## URL 処理コールバックの実装

PushSDK は、購読者が通知とやり取りしたときに呼び出されるコールバックを提供します。これらのコールバックは、通知を開いた後に購読者が自動的に適切なアクティビティへ移動するように実装する必要があります。

{% hint style="danger" %}
すべての SDK コールバックは、アプリケーションのメイン `onCreate` メソッド内にまとめて配置し、すべての通知イベントを適切に処理できるようにすることを推奨します。
{% endhint %}

SDK が通知の開封イベントを受け取ると、下記のいずれかのコールバックを、アプリ内の適切なアクティビティへ購読者を誘導するために使用できるパラメータ付きで呼び出そうとします。

これらのコールバックを実装するには、SDK の `registerNotificationLifecycleCallbacks` メソッドを呼び出し、その中でコールバックを実装するクラスが必要です。

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

```kotlin
PushSDK.registerNotificationLifecycleCallbacks(object : PNNotificationLifecycleCallbacks {
    // ここに関数のオーバーライドを追加
})
```

{% endtab %}

{% tab title="Java" %}

```java
PushSDK.registerNotificationLifecycleCallbacks(new PNNotificationLifecycleCallbacks() {
    // ここに関数のオーバーライドを追加
});
```

{% endtab %}
{% endtabs %}

たとえば、通知にランディング URL が添付されており、アプリ内での購読者の遷移を処理するコールバックを実装した場合、 `onCreate` メソッドのコードは次のようになります:

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

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

class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()

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

        PushSDK.PushNotifications.showPermissionPrompt(completion = { granted, response, error ->
            error?.let {
                println("権限リクエストでエラーが発生しました: $error")
                return@showNativeNotificationPermissionPrompt
            }

            println("権限が付与されました: $granted, response: $response")
        })

        PushSDK.registerNotificationLifecycleCallbacks(object : PNNotificationLifecycleCallbacks {
            override fun onPushSDKDidReceiveNotificationDestination(
                destination: String,
                interaction: PNNotificationInteraction
            ): Boolean {
                // 宛先（ランディング URL）用のアクティビティを開きます。これは
                // アプリ独自のタスクで開きます。FLAG_ACTIVITY_NEW_TASK は interaction.context では任意です。
                interaction.context.startActivity(
                    Intent(interaction.context, ArticleActivity::class.java)
                        .setData(Uri.parse(destination))
                )

                // SDK にナビゲートしないよう通知するために true を返します
                return true
            }
        })
    }

}
```

{% endtab %}

{% tab title="Java" %}

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

class MainApplication extends Application {

    @Override()
    public void onCreate() {
        super.onCreate();

        PushSDK.setLogLevel(PNLogLevel.INFO);
        PushSDK.setConfiguration("YOUR_APP_KEY", this);

        PushSDK.PushNotifications.showPermissionPrompt((granted, response, error) -> {
            if (error != null) {
                System.out.printf("権限リクエストでエラーが発生しました: %s", error);
            } else {
                System.out.printf("権限が付与されました: %b, response: %s" ,granted, response);
            }
            
            return null;
        });

        PushSDK.registerNotificationLifecycleCallbacks(new PNNotificationLifecycleCallbacks() {
            @Override
            public boolean onPushSDKDidReceiveNotificationDestination(@NonNull String destination, @NonNull PNNotificationInteraction interaction) {
                // 宛先（ランディング URL）用のアクティビティを開きます。これは
                // アプリ独自のタスクで開きます。FLAG_ACTIVITY_NEW_TASK は interaction.getContext() では任意です。
                Intent intent = new Intent(interaction.getContext(), ArticleActivity.class)
                        .setData(Uri.parse(destination));
                interaction.getContext().startActivity(intent);

                // SDK にナビゲートしないよう通知するために true を返します
                return true;
            }
        });
    }

}
```

{% endtab %}
{% endtabs %}

## 通知インタラクションのコールバック

### URI/URL 宛先で開かれた通知

{% hint style="info" %}
このコールバックは、URL を直接開くだけでは適切に処理できない、添付されたランディング URL のカスタム解析や変更が必要な場合に使用します。
{% endhint %}

このコールバックは、宛先ランディング URL が添付された通知が開かれたときに呼び出されます。購読者は、提供されたランディング URL を表すビューへ誘導される必要があります。

このメソッドは Boolean の応答を期待します。応答が `true` なら SDK はナビゲーションしません。アプリが購読者を誘導し、SDK はアプリが画面上に表示されていることだけを確認します。応答が `false` なら SDK は購読者を宛先 URL に遷移させようとします。

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

```kotlin
override fun onPushSDKDidReceiveNotificationDestination(
    destination: String,
    interaction: PNNotificationInteraction
): Boolean {
    // 宛先（ランディング URL）を使用して、アプリケーション内のアクティビティへ移動します

    // SDK にナビゲートしないよう通知するために true を返します
    return true
}
```

{% endtab %}

{% tab title="Java" %}

```java
@Override
public boolean onPushSDKDidReceiveNotificationDestination(@NonNull String destination, @NonNull PNNotificationInteraction pnNotificationInteraction) {
    // 宛先（ランディング URL）を使用して、アプリケーション内のアクティビティへ移動します

    // SDK にナビゲートしないよう通知するために true を返します
    return true;
}
```

{% endtab %}
{% endtabs %}

### 通知を自分でルーティングする

返り値が `true`の場合、アプリが通常どおりナビゲーションする方法で購読者を誘導します:

* **アプリが独自のアクティビティを開く場合** 宛先に対しては、コールバック内から起動します。起動元は `interaction.context` またはアプリケーションコンテキストから次を使って起動します: `Intent.FLAG_ACTIVITY_NEW_TASK`。アクティビティはアプリ独自のタスクで開かれるため、戻るとアプリに戻ります。
* **アプリがすでに実行中のアクティビティ内で画面を切り替える場合** — シングルアクティビティのアプリ、または Jetpack Compose ナビゲーションでルーティングするアプリ — なら、アプリ内イベントと同様にナビゲートしてください。SDK がアプリを前面に出します。

{% hint style="warning" %}
`interaction.context` はコールバック実行中のみ有効です。後でアクティビティを起動するために保持しないでください（たとえば非同期検索の後など）。後続のナビゲーションは、アプリケーションコンテキストから次を使って開始します: `Intent.FLAG_ACTIVITY_NEW_TASK`.
{% endhint %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
