> 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/xiang-xi-she-ding/serufumanjido.md).

# セルフマネージド統合

統合を容易にするため、PushSDK には自動的に次の拡張が含まれます。 `FirebaseMessagingService` クラスです。ただし、独自のサービスを持っていて、次のようないくつかのシナリオで PushSDK に呼び出しを転送する必要がある場合があります。

* 他の SDK との競合
* 競合するサードパーティ製開発ソリューション
* 当社のメッセージングサービスが、既存のアーキテクチャと競合しています

{% hint style="info" %}
FirebaseMessaging との統合をカスタマイズする必要がある場合にのみ、自己管理型の統合を検討することをお勧めします。自己管理型の統合を選択する場合は、PushSDK の新しいリリースで手動で呼び出す必要のある追加メソッドが増えていないことを確認する必要があります。
{% endhint %}

### 独自のメッセージングサービスを統合する

まず、PushSDK によって自動的に追加されるサービスを削除し、アプリのマニフェストファイルに独自のサービスを追加します。

{% tabs %}
{% tab title="AndroidManifest.xml" %}

```xml
<manifest 
    ...
    xmlns:tools="http://schemas.android.com/tools"
>
    <!-- PushSDK のメッセージングサービスを削除 -->
    <service
        android:name="com.pushly.android.PNMessagingService"
        tools:node="remove" />

    <!-- 独自のメッセージングサービスを追加 -->
    <service
        android:name=".MyMessageService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
</manifest>
```

{% endtab %}
{% endtabs %}

独自のメッセージングサービスを追加したら、自動では処理されなくなったメソッドを呼び出すために、PushSDK への呼び出しも行う必要があります。以下のすべてのメソッドを実装しないと、PushSDK が正しく動作しない場合があります。

手動で呼び出す必要があるメソッドは次のとおりです。

* `PushSDK.handleOnNewToken(context: Context, token: String)`
* `PushSDK.handleOnMessageReceived(context: Context, message: RemoteMessage)`

メッセージングサービス自体を、 `コンテキスト` （a `FirebaseMessagingService` は `コンテキスト`).

{% hint style="warning" %}
**次の `コンテキスト` オーバーロードを使用します。** プッシュが終了済みのアプリに配信されると、FCM はメッセージングサービスを実行するためだけにアプリのプロセスを起動します。この時点では、Activity もホストコードも SDK をまだ設定していません。 `コンテキスト` オーバーロードは、コールバックを処理する前に保存済みのアプリキーから SDK を初期化するため、通知が表示され、更新されたトークンが記録されます。従来の `handleOnNewToken(token)` および `handleOnMessageReceived(message)` 形式ではこれを行えず、非推奨です。これらを使用すると、終了済みのアプリに配信されたプッシュは破棄されます。
{% endhint %}

### メッセージングサービスの例

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

<pre class="language-kotlin"><code class="lang-kotlin"><strong>override fun onNewToken(token: String) {
</strong><strong>    super.onNewToken(token)
</strong>    PushSDK.handleOnNewToken(this, token)
}

override fun onMessageReceived(message: RemoteMessage) {
    super.onMessageReceived(message)
    PushSDK.handleOnMessageReceived(this, message)
}
</code></pre>

{% endtab %}

{% tab title="Java" %}

```java
@Override
public void onNewToken(@NonNull String token) {
    super.onNewToken(token);
    PushSDK.handleOnNewToken(this, token);
}

@Override
public void onMessageReceived(@NonNull RemoteMessage message) {
    super.onMessageReceived(message);
    PushSDK.handleOnMessageReceived(this, message);
}
```

{% endtab %}
{% endtabs %}


---

# 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, and the optional `goal` query parameter:

```
GET https://documentation.pushly.com/pushly-ja/integration/implementation-steps/android/xiang-xi-she-ding/serufumanjido.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
