> 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/integration/implementation-steps/android/advanced/self-managed-integration.md).

# Self-Managed Integration

To make integrations easier the PushSDK automatically includes an extension of the `FirebaseMessagingService` class. However, you may have your own service and need to forward calls to the PushSDK in several scenarios including:

* Conflicts with other SDKs
* Conflicting third party development solutions
* Our messaging service conflicts with your existing architecture

{% hint style="info" %}
We suggest that you only consider a self-managed integration if you need to customize the integration with FirebaseMessaging. If you choose to use a self-managed integration you will need to ensure that any new releases to the PushSDK do not add additional methods that must be called manually.
{% endhint %}

### Integrating Your Own Messaging Service

First you will want to remove the service automatically added by the PushSDK and add your own to the app manifest file.

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

```xml
<manifest 
    ...
    xmlns:tools="http://schemas.android.com/tools"
>
    <!-- Remove the PushSDK messaging service -->
    <service
        android:name="com.pushly.android.PNMessagingService"
        tools:node="remove" />

    <!-- Add your own messaging service -->
    <service
        android:name=".MyMessageService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
</manifest>
```

{% endtab %}
{% endtabs %}

Once you have added your own messaging service you'll also be required to place calls to the PushSDK to invoke the methods that are no longer automatically handled. If you do not implement all of the following methods the PushSDK may not function properly.

The methods you must call manually are:

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

### Messaging Service Example

{% 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(token)
}

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

{% endtab %}

{% tab title="Java" %}

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

@Override
public void onMessageReceived(@NonNull RemoteMessage message) {
    super.onMessageReceived(message);
    PushSDK.handleOnMessageReceived(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/integration/implementation-steps/android/advanced/self-managed-integration.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.
