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

# Android

<Frame>
  <img src="https://mintcdn.com/asapp/aK0YOQVZSULmKYJl/image/uuid-6b0545f1-bbc3-d676-aebd-2e478cc8406f.png?fit=max&auto=format&n=aK0YOQVZSULmKYJl&q=85&s=6c090683e346494299829f92a2b504f7" width="1080" height="813" data-path="image/uuid-6b0545f1-bbc3-d676-aebd-2e478cc8406f.png" />
</Frame>

## Requirements

Chat Instead requires ASAPP Android Chat SDK 8.0.0 or later, and a valid phone number. Before you proceed, make sure you configure it [correctly](/agent-desk/integrations/android-sdk).

## Phone Formats

Chat Instead accepts a wide variety of formats. See [tools.ietf.org/html/rfc3966](https://tools.ietf.org/html/rfc3966) for the precise definition. For example, Chat Instead accepts: "+1 (555) 555-5555" and "555-555-5555".

## Getting Started

There are two ways to add Chat Instead. The easiest way is to add the `ASAPPChatInsteadButton` to the layout and call the `ASAPPChatInsteadButton.init`. Alternatively, you can manage the lifecycle yourself.

### 1. Add an ASAPPChatInsteadButton

You can add this button to any layout, like any other [AppCompatButton](https://developer.android.com/reference/androidx/appcompat/widget/AppCompatButton).

```json theme={null}
<com.asapp.chatsdk.views.ASAPPChatInsteadButton
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_chat_instead"
    />
```

After that, be sure to call the `ASAPPChatInsteadButton.init` method. Only the phone number is mandatory. Optionally, you can overwrite the `ASAPPChatInsteadButton.onChannel` and the `ASAPPChatInsteadButton.onError` properties of the button.

### 2. Manual Setup of ASAPPChatInstead

1. Initialize Chat Instead
   Somewhere after the `ASAPP.init` call:
   ```json theme={null}
   val chatInstead = ASAPPChatInstead.create(phoneNumber)
   ```
   to initialize Chat Instead. Depending on cache, this will trigger a network call so channels are "immediately" available to the user once the fragment is displayed.
   Along with an optional header and a chat icon, you can pass callbacks to be notified when a channel is tapped or an error on a channel happens.
   ASAPP makes both callbacks after Chat Instead tries to act on the tap.
2. Display Channels
   With the instance returned by `ASAPPChatInstead.init`, call `ASAPPChatInstead.show` whenever you want to display the [BottomSheetDialogFragment](https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetDialogFragment?hl=en). Depending on cache, this might show a loading state.
3. Clear Chat Instead (optional)
   You can interrupt the Chat Instead initial network call, if you call `ASAPPChatInstead.clear`. ASAPP advises you to add the call `onDestroy` for Activities and `onDetachedFromWindow` for Fragments.
   If you call `ASAPPChatInstead.clear` after you create the [BottomSheetDialogFragment](https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetDialogFragment?hl=en) view, it has no effect.

## Error Handling and Debugging

In the case of problems, look for logs with the "ASAPPChatInstead" tag. Be sure to call `ASAPP.setDebugLoggingEnabled(true)` to enable the logs.
Alternatively, you can set callbacks with `ASAPPChatInstead.init`.

### Troubleshoot Chat Instead Errors

#### Crash Caused by UnsupportedOperationException when Displaying the Fragment

This occurs whenever someone does not define `asapp_primary` in the style that the calling Activity uses. Please refer to **Customization > Colors**.

#### "Unknown Channel" in the Log or the onError Callback

Talk to your Implementation Manager at ASAPP. ASAPP's Backend sent a channel we don't know how to handle. You might need to upgrade the Android SDK version.

#### "Unknown Error" in the Log

Talk to your Implementation Manager at ASAPP. This might be a bug. Please attach logs and reproduction steps.

#### "Activity Context Not Found" in the Log

It means you are not sending the right context at `ASAPPChatInstead.show`.

## Tablet and Landscape Support

Chat Instead supports these configurations seamlessly.

## Customization

<Frame>
  <img src="https://mintcdn.com/asapp/aK0YOQVZSULmKYJl/image/uuid-7c077e80-61e2-93a7-1d0f-240e32c91769.png?fit=max&auto=format&n=aK0YOQVZSULmKYJl&q=85&s=630132c05c04f33c84714367d4bd72e7" width="787" height="444" data-path="image/uuid-7c077e80-61e2-93a7-1d0f-240e32c91769.png" />
</Frame>

### Header

By default, Chat Instead uses the text in `R.string.asapp_chat_instead_default_header`. You can send a different string when initializing Chat Instead, but the ASAPP Backend overwrites it if the call succeeds.

### Chat Icon

You can customize the SDK Chat channel icon. By default, the system tints it with `asapp_primary` and `asapp_on_primary`.

<Note>
  If you customize the icon, make sure to test how it looks in Night Mode (a.k.a. Dark Mode).
</Note>

### Colors

Chat Instead uses the ASAPP text styles and colors. For more information on how to customize, go to [Customization](../android-sdk/customization "Customization").

<Frame>
  <img src="https://mintcdn.com/asapp/COy3KdZUtsAnzs_4/image/uuid-961a0a3b-ce7b-5e66-626b-9d8c94629478.png?fit=max&auto=format&n=COy3KdZUtsAnzs_4&q=85&s=08f250e85d10a7979f7ef92c473a33fc" width="1247" height="466" data-path="image/uuid-961a0a3b-ce7b-5e66-626b-9d8c94629478.png" />
</Frame>

## Remote settings

Chat Instead receives configuration information from ASAPP's Backend (BE), in addition to the channels to display. The configuration enables/disables the feature and selects the device type (mobile, tablet, none). Contact your Implementation Manager at ASAPP if you have any questions.

<Note>
  It's important to know how the BE affects customization. If you provide a header, the BE overwrites it. On the other hand, the BE cannot overwrite the phone number.
</Note>

## Cache

Chat Instead will temporarily cache the displayed channels to provide a better user experience. The cache is warmed at instantiation. The information persists through phone restarts. As usual, it does not survive an uninstall or a "clear cache" in App info.
