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

# Android Push Configuration

> Configure Android push notifications in your Capacitor app including FCM setup and push registration.

# Basic Setup

Follow the basic setup outlined in this section to enable push notifications on an Android device using MoEngage.

* **FCM Setup on MoEngage Dashboard -** FCM Authentication is the method to enable sending push notifications to your app installed on Android devices. Use the methods mentioned in [this article](/developer-guide/android-sdk/push/basic/fcm-authentication) to authenticate MoEngage to access Firebase services.
* **Adding metadata for push notification -** Set the small icon and large icon drawable and other options to handle push notifications using the methods available in [this article](/developer-guide/components-for-sdk/push-notification/android-push-configuration-for-hybrid-applications#adding-metadata-for-push-notification).
* **Android Notification Runtime Permissions** - When the application is running on Android 13 to show notifications to the user, applications would need to request the user for notification permission. Refer to the methods available in [this article](/developer-guide/react-native-sdk/push/basic/android-notification-runtime-permissions) to handle permission requests.
* **Push Registration and Receiving** - To use Push Notification in your React Native application, you must configure Firebase. Configuring Firebase steps will depend on how you want to integrate it. MoEngage recommends leaving the push handling to MoEngage SDK, as the best practices are properly integrated. You can also handle the push at your app level. In any case, look at the following section that applies to you and finish the integration steps.

<Tabs>
  <Tab title="Let MoEngage handle Push(Recommended)">
    **Add messaging service**\
    You must add the messaging service to the Manifest file for MoEngage SDK to show the notifications. Refer to this document [here](/developer-guide/android-sdk/push/basic/push-token-registration-and-display#push-token-registration-and-display-by-moengage-sdk).

    **Callback on token registration (optional)**\
    To get a callback whenever a new token is registered or refreshed, refer to the method [here](/developer-guide/android-sdk/push/basic/push-token-registration-and-display#push-token-registration-and-display-by-moengage-sdk).

    **Notification Clicked Callback**

    To receive a callback whenever a push is clicked and for custom handling redirection, use the method [in this article](/developer-guide/android-sdk/push/advanced/callbacks-and-customisation#notification-received-callback).
  </Tab>

  <Tab title="You handle Push via Android Native">
    **How to opt out of MoEngage Registration?**\
    The MoEngage SDK attempts to register for a push token; since your application handles push, you need to opt out of SDK's token registration using the method in [this article](/developer-guide/android-sdk/push/basic/push-token-registration-and-display#pass-the-push-token-to-moengage-sdk).

    **Pass the Push Token To MoEngage SDK** - After receiving the push token from FCM, use the method in [this article](/developer-guide/android-sdk/push/basic/push-token-registration-and-display) to pass the Push Token to the MoEngage SDK to set it in the MoEngage platform.

    **Passing the Push payload to the MoEngage SDK** - After receiving the push payload on the app, use the method in [this article](/developer-guide/android-sdk/push/basic/push-token-registration-and-display#passing-the-push-payload-to-the-moengage-sdk)to send out push notifications to the device.
  </Tab>

  <Tab title="You handle Push via Capacitor (Not Recommended)">
    <Warning>
      MoEngage recommends using the Android native APIs to pass the push payload to the MoEngage SDK instead of the React-Native/Javascript APIs. React-Native Engine might not get initialized if the application is killed or if the notification is not sent at a high priority.
    </Warning>

    * [Pass the Push Token To MoEngage SDK](/developer-guide/capacitor-sdk/push/basic/android-push-configuration#passing-push-token)
    * [Pass the Push payload to the MoEngage SDK](/developer-guide/capacitor-sdk/push/basic/android-push-configuration#passing-push-payload)
    * [Callbacks and customizations](/developer-guide/react-native-sdk/push/basic/android-push-configuration#customizing-push-notification)
  </Tab>
</Tabs>

 

# Capacitor APIs

 

<Warning>
  We highly recommend you to use the Android native APIs for passing the push payload to the MoEngage SDK instead of the Capacitor APIs. Capacitor Engine might not get initialised if the application is killed or if the notification is not sent at a high priority.
</Warning>

## Passing Push Token

<CodeGroup>
  ```javascript TypeScript theme={null}
  import { MoECapacitorCore } from 'capacitor-moengage-core'
  // pass the push token as a string
  passFcmPushToken({ token: "TOKEN", appId: "YOUR_Workspace_ID" });
  ```
</CodeGroup>

## Passing Push Payload

<CodeGroup>
  ```javascript TypeScript theme={null}
  import { MoECapacitorCore } from 'capacitor-moengage-core'
  // pass the push payload object
  passFcmPushPayload(payload: object, appId: "YOUR_WORKSPACE_ID" });
  ```
</CodeGroup>

<Warning>
  We highly recommend you to use the Android native APIs for passing the push payload to the MoEngage SDK instead of the Capacitor APIs. Capacitor Engine might not get initialised if the application is killed or if the notification is not sent at a high priority.
</Warning>

# Notification Runtime Permission

Android 13 (API level 33) and higher supports [runtime permission](https://developer.android.com/guide/topics/permissions/overview#runtime) for sending [non-exempt](https://developer.android.com/develop/ui/views/notifications/notification-permission#exemptions) (including Foreground Services (FGS)) notifications from an app `POST_NOTIFICATIONS`. This change helps users focus on the notifications that are most important to them.

Refer to the [official documentation](https://developer.android.com/develop/ui/views/notifications/notification-permission) for more details.

The below-mentioned APIs are supported from Plugin version **2.0.0**

When the application is running on Android 13 to show notifications to the user, applications would need to request the user for notification permission.

For applications integrating the MoEngage SDK, would need to 

* Notify the SDK of the permission request's response from the user.
* If the application has already requested push permission(before MoEngage integration) help MoEngage set up notification channels for notification display.

## Notify SDK of permission result

Once the application requests the user for notification permission notify the SDK of the user response using the below API.

<CodeGroup>
  ```typescript Typescript theme={null}
  import { MoECapacitorCore} from 'capacitor-moengage-core'
  MoECapacitorCore.pushPermissionResponseAndroid({ isGranted: true/false });
  ```
</CodeGroup>

## Setup Notification Channels

If the application has already taken notification permission from the user call the below API to set up Notification Channels for showing push notifications.

<CodeGroup>
  ```typescript Typescript theme={null}
  import { MoECapacitorCore} from 'capacitor-moengage-core'
  MoECapacitorCore.setupNotificationChannelsAndroid();
  ```
</CodeGroup>

MoEngage SDK provides helper APIs to show the permission request to the end-user or navigate the user to the settings screen for enabling notifications.

Use the below API to show the permission request dialog to the user.

When using the below API SDK automatically tracks the response, sets up the required notification channel, etc, mentioned above.

<CodeGroup>
  ```typescript Typescript theme={null}
  import { MoECapacitorCore} from 'capacitor-moengage-core'
  MoECapacitorCore.requestPushPermissionAndroid();
  ```
</CodeGroup>

Use the below API to show navigate the user to the Notification Settings for the application on the device.

*Note*: Below Android 8(API level 26) the user is directed to the Application Info screen of your application.

<CodeGroup>
  ```typescript Typescript theme={null}
  import { MoECapacitorCore} from 'capacitor-moengage-core'
  MoECapacitorCore.navigateToSettingsAndroid();
  ```
</CodeGroup>

## Customizing Push notification

If required the application can customize the behavior of notifications by using Native Android code (Java/Kotlin). To learn more about the customization refer to the [Advanced Push Configuration](/developer-guide/android-sdk/push/advanced/callbacks-and-customisation) documentation.Instead of extending ***PushMessageListener*** as mentioned in the above document extend ***PluginPushCallback.***

Refer to the below documentation for Push Amp+, Push Templates, and Geofence.

* [Push Amplification](/developer-guide/android-sdk/push/optional/push-amplification)
* [Push Amp Plus](/developer-guide/android-sdk/push/optional/push-amp-plus/push-amp-plus-integration)
* [Push Templates](/developer-guide/android-sdk/push/optional/push-templates)
* [GeoFence Push](/developer-guide/android-sdk/push/optional/location-triggered)
