Device Phone Number API
Retrieve the device phone number using the WebToNative JavaScript API. Access native phone information for Android applications securely.
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).
Get Device Phone Number
Triggers the Google Phone Number Hint prompt on Android and returns the selected number through the callback.
window.WTN.getDevicePhoneNumber({
callback: function (response) {
console.log(response.phoneNumber);
},
});import { getDevicePhoneNumber } from "webtonative";
getDevicePhoneNumber({
callback: (response) => {
console.log(response.phoneNumber);
},
});Parameters:
callback
Function
No
Callback function invoked with the response.
Callback Response:
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:
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,
successwill befalse.Requires Google Play services on the device.
Last updated