> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifly.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# インターセプターでAndroidの通知を変更する

> Notifly Android SDKが通知を表示する前に、見た目や動作を変更します。

Notifly Android SDKを初期化した後に、通知インターセプターを登録します。インターセプターを使うと、SDKが通知を表示する前に見た目や動作を変更できます。

```kotlin theme={null}
package com.your.project

import android.app.Application
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import tech.notifly.Notifly
import tech.notifly.push.interfaces.INotificationInterceptor
import tech.notifly.push.interfaces.IPushNotification

class SampleApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        // Initialize Notifly SDK
        Notifly.initialize(
            context = applicationContext,
            projectId = BuildConfig.NOTIFLY_PROJECT_ID,
            username = BuildConfig.NOTIFLY_USERNAME,
            // 旧バージョンとの互換性のためのダミー値です。実際のパスワードやAPI Secret Keyはアプリに含めないでください。
            password = BuildConfig.NOTIFLY_USERNAME,
        )

        // Add Notifly notification interceptor
        Notifly.addNotificationInterceptor(object : INotificationInterceptor {
            override fun postBuild(
                builder: NotificationCompat.Builder,
                notification: IPushNotification
            ): NotificationCompat.Builder {
                // Customize the notification here
                builder.setColor(ContextCompat.getColor(applicationContext, R.color.purple_700))
                // You can add more customizations based on your requirements
                return builder
            }
        })
    }
}
```

## インターセプターのインターフェース

`INotificationInterceptor`の`postBuild`を実装します。このメソッドは2つの引数を受け取ります。

* `builder: NotificationCompat.Builder`。ビルダーを変更して通知の見た目や動作を調整します。
* `notification: IPushNotification`。通知の情報を参照し、適用する変更を決めます。

`postBuild`から変更後のビルダーを返します。

> [!NOTE]
>
> Android 8.0（APIレベル26）以降では、通知チャネルの設定が優先されます。たとえば、チャネルに通知音が設定されていると、`builder.setSound()`の設定が反映されない場合があります。通知の設定を変更する際は、通知チャネルの設定も確認してください。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.