> ## Documentation Index
> Fetch the complete documentation index at: https://social-b97141fb-auto-generate-llmstxt.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Android Push Notifications

> Connect Android push tokens to the current social.plus Android SDK.

Android push setup has two separate responsibilities:

1. Configure the Android app and provider, such as Firebase Cloud Messaging.
2. Connect the provider token and signed-in device to social.plus through the SDK.

<Warning>
  Push delivery also requires server-side credentials in the social.plus Console. The client SDK can register a device only after the platform push provider and console configuration are complete.
</Warning>

## SDK Surface

| Purpose                                      | Current Android API                            | When to call                                                                    |
| -------------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------- |
| Store an FCM token with the SDK push adapter | `AmityFcm.create().setup(fcmToken)`            | When Firebase gives your app an FCM token, including token refresh.             |
| Register the current signed-in device/user   | `AmityCoreClient.registerPushNotification()`   | After the SDK has a signed-in user session.                                     |
| Unregister the current device/user           | `AmityCoreClient.unregisterPushNotification()` | On sign-out or when this installation should stop receiving push notifications. |

## Parameters

| Name          | Type     | Required              | Description                                                                                           |
| ------------- | -------- | --------------------- | ----------------------------------------------------------------------------------------------------- |
| `fcmToken`    | `String` | Yes                   | The FCM registration token returned by Firebase for this app installation.                            |
| `baiduApiKey` | `String` | Only for Baidu builds | API key passed to the optional Baidu push adapter when that module is included in your Android build. |

## 1. Configure FCM

Follow the Android and Firebase setup flow for your app:

* Add `google-services.json` to your app module.
* Apply the Google Services Gradle plugin.
* Add Firebase Messaging using the version recommended for your Firebase setup.
* Request `POST_NOTIFICATIONS` at runtime on Android 13+ when your product needs visible notifications.

If your Android dependency setup installs SDK modules separately, include the FCM push adapter with the same version as your social.plus Android SDK:

```gradle Gradle theme={null}
dependencies {
    implementation 'co.amity.android:amity-push-fcm:x.y.z'
}
```

<Info>
  Use the same `x.y.z` version you use for `co.amity.android:amity-sdk`. If your package already bundles the FCM adapter, do not add a duplicate dependency.
</Info>

## 2. Upload Provider Credentials

In the social.plus Console, open **Settings > Push Notifications** and upload the Firebase service account JSON for your app. Without this server-side credential, client registration can succeed while push delivery still fails.

## 3. Connect the FCM Token

Pass every current FCM token to the SDK push adapter. Do this for the initial token and every token refresh.

<CodeGroup>
  ```kotlin Android theme={null}
  import com.amity.socialcloud.sdk.push.AmityFcm

  val fcmToken = "fcm-token"

  AmityFcm.create()
      .setup(fcmToken)
      .subscribe()
  ```
</CodeGroup>

The Android sample app calls the same adapter from `FirebaseMessagingService.onNewToken(token)`.

## 4. Register the Signed-In Device

After the SDK has a signed-in user session and the app has connected the FCM token, register the current device/user with social.plus.

<CodeGroup>
  ```kotlin Android theme={null}
  AmityCoreClient.registerPushNotification()
      .doOnComplete {
          // Device registration completed.
      }
      .doOnError { error ->
          // Handle registration error.
      }
      .subscribe()
  ```
</CodeGroup>

Call unregister when the user signs out or disables push for this installation.

<CodeGroup>
  ```kotlin Android theme={null}
  AmityCoreClient.unregisterPushNotification()
      .doOnComplete {
          // Device unregistration completed.
      }
      .doOnError { error ->
          // Handle unregistration error.
      }
      .subscribe()
  ```
</CodeGroup>

<Note>
  `registerPushNotification()` has no token parameter in the current Android SDK. The token is handled by the push adapter through `AmityFcm.create().setup(fcmToken)`.
</Note>

## Optional Baidu Adapter

The Android source also contains an optional Baidu push adapter, `AmityBaidu.create(context).setup(baiduApiKey)`, for builds that include the Baidu push module. The default Android SDK build path uses the FCM adapter, so treat Baidu setup as a China-market build decision and verify the module distribution before enabling it.

## Setup Checklist

* FCM is configured in the Android app.
* The Firebase service account JSON is uploaded in the social.plus Console.
* The latest FCM token is passed to `AmityFcm.create().setup(fcmToken)`.
* The signed-in device/user is registered with `AmityCoreClient.registerPushNotification()`.
* The device is unregistered on sign-out when the app should stop receiving push notifications for that user.
