> For the complete documentation index, see [llms.txt](https://api.omicall.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.omicall.com/sdk/mobile-sdk/android-sdk/lang-nghe-cac-su-kien.md).

# Lắng nghe các sự kiện

### Thực hiện cuộc gọi

&#x20;Để thực hiện một cuộc gọi ra chúng ta gọi hàm như sau

```java
InCallActivity.startInCall(
                requireContext(),
                phoneNumber
            )

```

### &#x20;<a href="#user-content-handle-call-by-yourself" id="user-content-handle-call-by-yourself"></a>

### Lắng nghe các sự kiện <a href="#user-content-listeners" id="user-content-listeners"></a>

Khi sử dụng SDK các sự kiện từ SDK sẽ được notification ra bằng cách lắng nghe các lớp&#x20;

* `OmiListener` Lắng nghe các sự kiện trong cuộc gọi

`OmiListener`&#x20;

<table><thead><tr><th>Tên hàm</th><th width="214">Mô tả </th><th>Ví dụ</th></tr></thead><tbody><tr><td><code>onAccountRegistered</code></td><td>Sự kiện được gọi khi tài khoản đăng nhập thành công</td><td></td></tr><tr><td>onAccountRegisterFailed</td><td>Sự kiện được gọi khi tài khoản đăng nhập thất bại</td><td></td></tr><tr><td>onCallEstablished</td><td>Sự kiện được gọi khi cuộc gọi được thiết lập thành công</td><td></td></tr><tr><td>onCallEnd</td><td>Sự kiện được gọi khi cuộc gọi kết thúc</td><td></td></tr><tr><td>incomingReceived</td><td>Sự kiện được gọi khi có cuộc gọi đến</td><td></td></tr><tr><td>onRinging</td><td>Cuộc gọi kết nối thành công đang đổ chuông</td><td></td></tr><tr><td>onConnectionTimeout</td><td>Cuộc gọi kết nối thất bại do không nhận được phản hồi của máy chủ </td><td></td></tr><tr><td>onHold</td><td>Cuộc gọi bị giữ lại</td><td><p></p><pre><code>OmiClient.instance.toggleHold()
</code></pre><p></p></td></tr><tr><td>onMuted</td><td>Cuộc gọi bị tắt âm thanh</td><td><pre><code>OmiClient.instance.toggleMute()
</code></pre></td></tr></tbody></table>

để làm việc này chúng ta cần thực hiện như sau:

```java
OmiClient.instance.setListener(OmiListener)
```

### Thông báo cuộc gọi đến <a href="#user-content-handle-call-by-yourself" id="user-content-handle-call-by-yourself"></a>

Initialize SDK with customUI parme set to true

Thông thường SDK sẽ tự có màn hình để hiển thị cuộc gọi đến như sau:

<img src="/files/YI0c0ox2EW1L6XiXyA03" alt="" data-size="original">

Trường hợp bạn muốn mình tự Custom màn hình này thì có thể tuỳ chỉnh cấu hình SDK như sau:

```java
OmiClient(requireContext()).initSDK(
    userName,
    password,
    realm,
    customUI = true
)
```

Sau đó chúng ta sẽ cài đặt Listenner để lắng nghe sự kiện thông báo cuộc gọi tới như sau:

```java
OmiClient.instance.setListener(OmiListener)
```

### Các sự kiện khi cuộc gọi diễn ra <a href="#user-content-actions-when-in-a-call" id="user-content-actions-when-in-a-call"></a>

Các sự kiện chúng ta có thể thực hiện để can thiệp vào một cuộc gọi bao gồm :

&#x20;

<table><thead><tr><th>Tên hàm</th><th>Mô tả</th><th>Ví dụ</th></tr></thead><tbody><tr><td>pickUp</td><td>chấp nhận cuộc gọi tới</td><td><pre><code>OmiClient.instance.pickUp()
</code></pre></td></tr><tr><td>decline</td><td>Từ chối cuộc gọi</td><td><p></p><pre><code>OmiClient.instance.decline()
</code></pre><p></p></td></tr><tr><td>hangup</td><td>Tự chối cuộc gọi </td><td><p></p><pre><code>OmiClient.instance.hangUp()
</code></pre><p></p></td></tr><tr><td>toggleHold</td><td>Giữ cuộc gọi hiện tại </td><td><p></p><pre><code>OmiClient.instance.toggleHold()
</code></pre></td></tr><tr><td>toggleMute</td><td>Tắt âm thanh cuộc gọi hiện tại</td><td><pre><code>OmiClient.instance.toggleMute()
</code></pre></td></tr></tbody></table>


---

# 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://api.omicall.com/sdk/mobile-sdk/android-sdk/lang-nghe-cac-su-kien.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.
