# Device Phone Number

Retrieves a phone number linked to the user's Google account on the device. On Android, this uses Google's Phone Number Hint, which shows a system prompt allowing the user to pick from phone numbers associated with their signed-in Google account(s).

{% hint style="info" %}
You'll need to import the javascript file in your website before starting from this [link](https://docs.webtonative.com/javascript-apis/getting-started).
{% endhint %}

{% hint style="info" %}
**Platform support:** Android only.
{% endhint %}

## Get Device Phone Number

Triggers the Google Phone Number Hint prompt on Android and returns the selected number through the callback.

{% tabs %}
{% tab title="Plain Javascript" %}

```javascript
window.WTN.getDevicePhoneNumber({
  callback: function (response) {
    console.log(response.phoneNumber);
  },
});
```

{% endtab %}

{% tab title="ES5+" %}

```javascript
import { getDevicePhoneNumber } from "webtonative";

getDevicePhoneNumber({
  callback: (response) => {
    console.log(response.phoneNumber);
  },
});
```

{% endtab %}
{% endtabs %}

**Parameters:**

| Key        | Type       | Required | Description                                  |
| ---------- | ---------- | -------- | -------------------------------------------- |
| `callback` | `Function` | No       | Callback function invoked with the response. |

**Callback Response:**

| Key           | Type               | Description                                                                                  |
| ------------- | ------------------ | -------------------------------------------------------------------------------------------- |
| `type`        | `String`           | Always `"getDevicePhoneNumber"`.                                                             |
| `success`     | `Boolean`          | `true` if a phone number was selected and retrieved successfully, `false` otherwise.         |
| `phoneNumber` | `String` or `null` | The phone number selected by the user from the Google account hint. `null` on failure.       |
| `error`       | `String` or `null` | `null` on success. Error message describing what went wrong (e.g., user dismissed the hint). |
| `error_code`  | `String` or `null` | `null` on success. A short error code identifying the failure case.                          |

**Example:**

```javascript
window.WTN.getDevicePhoneNumber({
  callback: function (response) {
    if (response.success && response.phoneNumber) {
      console.log("Selected phone number:", response.phoneNumber);
    } else {
      console.error(
        "Failed to get phone number:",
        response.error_code,
        response.error
      );
    }
  },
});
```

**Notes:**

* Works on **Android only**. iOS will not invoke the callback.
* Phone numbers come from the user's **Google account(s) signed in on the device**, not from the SIM. If the user has no phone number linked to their Google account, the hint prompt may show no options.
* The user must explicitly tap a number in the Google hint sheet — if they dismiss the sheet, `success` will be `false`.
* Requires Google Play services on the device.


---

# Agent Instructions: 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:

```
GET https://docs.webtonative.com/javascript-apis/device-phone-number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
