kony.phone Namespace
The kony.phone
namespace provides your apps with the ability to access the phone functionality of the user's device, if it is present on the device. The kony.phone
namespace provides you with the following API elements:
Functions
The kony.phone
namespace contains the following functions:
Adds a new event to the device calendar.
Syntax
kony.phone.addCalendarEvent(eventDetails);
Input Parameters
eventDetails
A JavaScript object that contains the following key-value pairs.
Key | Value |
---|---|
summary | A string that contains a short description of the event. |
start | A string that holds the start date and time for the event. The format for date is "dd/mm/yyyy", and time is "hh:mm:ss". This must be less than the date and time in the finish key, |
finish | A string that holds the finish date and time for the event. The format for date is "dd/mm/yyyy", and time is "hh:mm:ss". This must be greater than the date and time in the start key. |
alarm | An optional number that specifies the time in seconds before the start time when the phone must trigger an alarm. This key can be omitted if your app does not need to specify an alarm time. |
note | A string that contains the long description of the event. |
integer | A integer that defines the occurrence of a event. |
access | A string that indicated the privacy setting for the event. The values can be public , private , or confidential |
repeatConfig - Optional
A dictionary that indicates the repeat frequency and endRecurrence values for the event. The dictionary contains two values: repeat and endRecurrence.
repeat
A constant that indicates the repeat frequency. The values are as follows:
-
constants.CALENDAREVENT_REPEAT_NONE
-
constants.CALENDAREVENT_REPEAT_DAILY
-
constants.CALENDAREVENT_REPEAT_WEEKLY
-
constants.CALENDAREVENT_REPEAT_MONTHLY
-
constants.CALENDAREVENT_REPEAT_YEARLY
endRecurrence [Optional]
A string that stores the recurrence end date and time for the event. The format for the end date and time is "dd/mm/yyyy hh:mm:ss". This date must be greater than the start date and time. For native iOS, if you do not specify the endRecurrence value, the events will repeat for 2 years.
This allows you to set the interval to repeat the event. It must have a positive integer as value. The default value is 1.
For example, to create a quarterly event, configure ‘repeat’ as constants.CALENDAREVENT_REPEAT_MONTHLY and ‘interval’ as '3'. The repeat event will be created in every 3 months(quarterly).
To create a bi-weekly event, configure ‘repeat’ as constants.CALENDAREVENT_REPEAT_WEEKLY and ‘interval’ as '2'. The repeat event will be created in every 2 weeks (biweekly).
The following example shows how to add quarterly repeat event.
Example
//Sample code to add the Input Parameter Interval in the add calendar event to the device
addCalendarEvent argument
var eventobj = {
summary: "Event started",
start: this.startTime,
finish: this.finishTime,
alarm: 40,
access: "public",
“repeatConfig“:{
“repeat“:constants.CALENDAREVENT_REPEAT_MONTHLY,
“interval“: 3,
“endRecurrence”:endDate
}
};
kony.phone.addCalendarEvent(eventobj);
function addCalendarEvent() { try { alert("calendar event is about to start"); var evtobj = { summary: "Event started", start: "15/04/2012 11:23:45", finish: "16/04/2012 12:59:45", alarm: 40, note: "Event will end at 12.59 PM", access: "public", repeatConfig: { repeat: constants.CALENDAREVENT_REPEAT_MONTHLY, endRecurrence: ”21/12/2013 13:00:00” } } kony.phone.addCalendarEvent(evtobj); //Adds an event to the device calendar } catch (PhoneError) { alert("error in addCalendarEvent:: " + PhoneError); } }
//To add the calendar event to the device using 'kony.phone.addCalendarEvent' API CalendarAddEvent: function(eventObj) { try { var today = new Date(); var dd = today.getDate(); var mm = today.getMonth() + 1; var yyyy = today.getFullYear(); var h = today.getHours(); var m = today.getMinutes(); var s = today.getSeconds(); if (dd & lt; 10) { dd = '0' + dd } if (mm & lt; 10) { mm = '0' + mm } var date = dd + '/ ' + mm + ' / ' + yyyy; var stime = h + ":" + (parseInt(m) + 2).toString() + ":" + s; this.startTime = date + " " + stime; var ftime = (parseInt(h) + 1).toString() + ":" + m + ":" + s; this.finishTime = date + " " + ftime; if (eventObj["text"] == "Add calendar event") { var evtobj = { summary: "Event started", start: this.startTime, finish: this.finishTime, alarm: 40, access: "public" }; kony.phone.addCalendarEvent(evtobj); alert("Calendar event is added with start time = " + this.startTime + ". Please open device calendar to observe this."); } else { var evtobj = { summary: "Event started", start: this.startTime, finish: this.finishTime, alarm: 40, access: "confidential" }; kony.phone.addCalendarEvent(evtobj); alert("Calendar event is added in confidential mode with start time = " + this.startTime + "."); } } catch (PhoneError) { alert("error in addCalendarEvent:: " + PhoneError); } }
Return Values
None
Exceptions
This function throws the following phone exceptions.
Exception | Description |
---|---|
2100 | Unable to send the Message |
2101 | Insufficient Permissions |
2102 | Cannot open mail, mail not configured |
2103 | Cannot open media gallery |
This function also throws the following general exceptions.
Constant | Description |
---|---|
100 | Invalid parameter type. |
101 | Invalid number of arguments. |
102 | Invalid input – thrown when the input is invalid based on the context. |
103 | Invalid operation – thrown when the operation is invalid based on the context. |
104 | Not supported error – thrown when the method is not supported at all. |
105 | Index out of range. |
106 | Unknown error |
Remarks
You can view a video on using the Calendar here.
Events cannot be added in the past.
When your app calls this function on Android, it must have both the READ_CALENDAR and WRITE_CALENDAR permissions. Due to Android limitations, when your app sets an alarm with this function the number of seconds are rounded to the nearest minute. Events are added to the local calendar with the calendar name as the application name. They cannot be synched to email accounts.
The time zone of events that your app adds is the same as the device's current time zone.
Platform Availability
- iOS
- Android version 4.0 and later
This API stops the ongoing vibration pattern on a device. This API is available from V8 SP3 onwards.
IMPORTANT: For Android, you must define the VIBRATE permission under Manifest Properties.
<uses-permission android:name="android.permission.VIBRATE" />
Syntax
kony.phone.cancelVibration();
Input Parameters
None
Example
kony.phone.cancelVibration();
Return Values
None
Platform Availability
- Android
When invoked, this API clears the broadcast receiver and the existing listeners that are registered to retrieve the one-time password (OTP) from the SMS message received.
Syntax
kony.phone.clearSMSListeners();
Input Parameters
Parameter | Description |
---|---|
SMSListenerType [Constant] - Optional |
The SMSListenerType value can be any of the following:
Depending on the parameter value, a specific listener type is cleared. If no type is specified, both type of listeners(if any) are cleared. |
NOTE: Ensure that you create an androidbuild.properties file in the project folder of your Quantum Visualizerworkspace, and add the following key: addSMSRetrieverSupport = UI
.
You can set the key to UI
or Non-UI
to fetch the required Gradle entries. To know more about adding Android properties to the androidbuild.properties file, click here.
Example
clearAll: function() { try { kony.phone.clearSMSListeners(); } catch (err) { alert("Error:: " + err); } }
Return Values
None
Exceptions
- 101 - Invalid type of arguments to the kony.phone.clearSMSListeners API
Platform Availability
- Android
App hash key is a hash string composed of the app's package name and the app's public key certificate. When invoked, this API generates a hash key that must be included in the SMS message sent from the server to the user's device.
For an app to receive the message callback, the hash key has to be correct.
NOTE: This API must be invoked only if type of SMS listener triggered is kony.phone.SMS_WITHOUT_USER_CONSENT
Syntax
kony.phone.generateAppHashKey()
Input Parameters
None
NOTE: Ensure that you create an androidbuild.properties file in the project folder of your Quantum Visualizerworkspace, and add the following key: addSMSRetrieverSupport = UI
.
You can set the key to UI
or Non-UI
to fetch the required Gradle entries. To know more about adding Android properties to the androidbuild.properties file, click here.
Example
generateAppHashKey: function() { var key = kony.phone.generateAppHashKey(); kony.print("AppHashkey: " + key); }
Return Values
Return Value | Description |
---|---|
appHashKey[ String ] |
Returns a hash key that has to be appended to the SMS message by server. |
Platform Availability
- Android
Enables your app to call the specified telephone number.
You can use this API to make calls to other numbers without leaving the application.
Syntax
kony.phone.dial(number);
Input Parameters
Parameter | Description |
---|---|
number | A string containing the phone number to call. Only numbers, +, - and space are treated as valid characters in this string. |
Example
dial: function() { var number = this.view.tbxDial.text; kony.phone.dial(number); },
Return Values
None
Exceptions
2101 - Insufficient Permissions
Remarks
When you make a call to the specified number using this API, the underlying OS is used to make the call. The call charges as imposed by the service provider are applicable.
On the iPhone simulator, this function is a dummy call. You need to test this function on an actual iPhone device.
Platform Availability
Not supported on iPad, Android Tablets, and Desktop Web platforms.
This function finds an event in the device's calendar.
Syntax
kony.phone.findCalendarEvents(evtobj);
Input Parameters
Parameter | Description |
---|---|
evtobj [Object] - Mandatory | A JavaScript object that can contain the following values: |
Example
var evtobj = { type: "starting", start: this.startTime, finish: this.finishTime }; var events = kony.phone.findCalendarEvents(evtobj);
Return Values
If no matching event is found, this function returns null. If matching events are found, this function returns an array of JavaScript objects containing the matching events. Each JavaScript object contains the following key-value pairs.
Key | Value |
---|---|
summary | A string that contains a short description of the event. |
start | A string that holds the start date and time for the event. The format for date is "dd/mm/yyyy", and time is "hh:mm:ss". This must be less than the date and time in the finish key, |
finish | A string that holds the finish date and time for the event. The format for date is "dd/mm/yyyy", and time is "hh:mm:ss". This must be greater than the date and time in the start key. |
alarm | An optional number that specifies the time in seconds before the start time when the phone must trigger an alarm. This key can be omitted if your app does not need to specify an alarm time. |
note | A string that contains the long description of the event. |
access | A string that indicated the privacy setting for the event. The values can be public , private , or confidential |
Exceptions
This function throws the following phone exceptions.
Exception | Description |
---|---|
2100 | Unable to send the Message |
2101 | Insufficient Permissions |
2102 | Cannot open mail, mail not configured |
2103 | Cannot open media gallery |
This function also throws the following general exceptions.
Constant | Description |
---|---|
100 | Invalid parameter type. |
101 | Invalid number of arguments. |
102 | Invalid input – thrown when the input is invalid based on the context. |
103 | Invalid operation – thrown when the operation is invalid based on the context. |
104 | Not supported error – thrown when the method is not supported at all. |
105 | Index out of range. |
106 | Unknown error |
Remarks
The search criteria in the type key in the evtobj parameter can be any of the following values.
READ_CALENDAR permission is needed to use this function.
This function is supported on Android 4.0 version and above (that is, Android API 14 and later). Invocation on Android version less than 4.0 ( that is, an Android API level earlier than 14) is ignored.
This function searches only those events that are added by the application.
Platform Availability
- iOS
- Android 4.0 or later
This API returns an array of constants that indicates possible actions for removing a particular event depending on the native support on the device. One of the values that this API returns must be passed as removeOption for kony.phone.removeCalendarEvent API.
Syntax
kony.phone.getRemoveEventOptions(eventHandle);
Input Parameters
Parameter | Description |
---|---|
eventHandle - Mandatory | Single event from the array of events that the kony.phone.findCalendarEvents API returns. |
Example
var removeOptions = kony.phone.getRemoveEventOptions(eventHandle);
Return Values
An array with possible constant values depending on native support in devices. The possible constants that will be returned as part of the array are as follows:
Constant | Description |
---|---|
CALENDAREVENT_REMOVE_THIS | Indicates that only one event must be deleted. |
CALENDAREVENT_REMOVE_THIS_AND_FUTURE | Indicates that the event as well as future events must be deleted. |
NOTE: Depending on the OS configuration of certain Android devices, any of these two values may not be applicable. So before passing any of these two values in the API, you must verify if the Android device supports the required value.
Platform Availability
- iOS
- Android
This API returns whether vibrator is supported on a device. This API is available from V8 SP3 onwards.
IMPORTANT: For Android, you must define the VIBRATE permission under Manifest Properties.
<uses-permission android:name="android.permission.VIBRATE" />
Syntax
kony.phone.hasVibratorSupport();
Example
hasVibratorSupport: function() { if (kony.phone.hasVibratorSupport() === true) { alert("The device contains a Vibration motor"); } },
Input Parameters
None
Return Values
Boolean is the return value.
Return Value | Description |
---|---|
true | The device supports vibrator. |
false | The device does not support vibrator. |
Platform Availability
- Android
This API allows the application to launch the native email client with predefined email addresses, subject, body, and attachments.
Syntax
kony.phone.openEmail(torecipients,ccrecipients, bccrecipients, subject, messagebody, ismessagebodyhtml, attachments, viewMode, filterEmailAppsOnly);
Input Parameters
Parameter | Description |
---|---|
torecipients [Array of Strings] - Mandatory |
List of email addresses to be included in the "to" list. For example, "john@example.com","stephen.joseph@kony.com", and "test@somecompany.com". |
ccrecipients [Array of Strings] - Optional |
List of email addresses to be included in the "cc" list. For example, "john@example.com","stephen.joseph@kony.com", and "test@somecompany.com". If you do not want to use this parameter, you can pass null value. |
bccrecipients [Array of Strings] - Optional |
List of email addresses to be included in the "bcc" list. For example, "john@example.com", "stephen.joseph@kony.com", and "test@somecompany.com". If you do not want to use this parameter, you can pass null value. |
subject [String]- Optional |
Subject to be part of the email. If you do not want to use this parameter, you can pass null value. |
messagebody [String] -Optional |
Body to be part of the email. If you do not want to use this parameter, you can pass null value. |
ismessagebodyhtml [Boolean] - Optional |
If you do not want to use this parameter, you can pass null value. When you pass null value, this parameter defaults to false.
|
attachments [Array of Objects] - Optional |
Each attachment is a Hash-table with the following key-value pairs. If you do not want to use the attachments parameter, you can pass null value.
NOTE: |
filterEmailAppsOnly [Boolean] - Optional |
Set this parameter to true to filter and list only email applications, which are shown in the Chooser dialog box. By default, the value of this parameter is false. If you do not want to use this parameter, you can pass a null value. NOTE: This property is only available on the Android platform. On Android 11 (Target SDK version 30, or later) devices, if you want to view a filtered list of email applications, add the following entry in the Project Settings > Native > Android Mobile/Tablet > Child tag entries under <manifest> tag field: <queries> <intent> <action android:name="android.intent.action.SENDTO" /> <data android:scheme="mailto"/> </intent> </queries> |
Example
emailSend: function() { kony.phone.openEmail(["kitchensinkapp@kony.com"], [""], [""], "Feedback on KitchenSink Application 1.1", "", false, []); }
Return Values
None
Exceptions
PhoneError
The following error codes are defined for Phone APIs
- 2100 - Unable to send the Message
- 2101 - Insufficient Permissions
- 2102 - Cannot open mail, mail not configured
- 2103 - Cannot open media gallery
Platform Availability
Available on all platforms except Desktop Web.
For these platforms you can launch the native email client by using Richtext widget with an href tag similar to the one shown below:
<a href="mailto:email@kony.com?subject=Foo&body=Bar">Email Me</a>
This API allows you to open the picture gallery of the mobile device and pick an existing picture.
You can use this API to use any of the multimedia resources (image files, audio files, or video files) available in the device media gallery within your application.
For iPad, openMediaGallery will show the Photos/Videos in the native popover. The popover can be anchored to a widget. The widget to which the popup should be anchored will be provided as a third parameter to openMediaGallery API.
You can view a video on using iPad Popover here.
Syntax
kony.phone.openMediaGallery(onselectioncallback, querycontext, PSP);
Input Parameters
Parameter | Description |
---|---|
onselectioncallback [Function] - Mandatory |
This callback function is invoked when a media is selected. The function receives rawbytes and permStatus as parameters.
Example function onSelectionCallback(rawbytes, permStatus, mimeType) { if(rawbytes != null) { //access the rawbytes alert(“file format: ”++mimeType); } else if (permStatus == kony.application.PERMISSION_DENIED) { alert(“Permission Denied to Access the Photo Gallery”); } } var querycontext = { mimeType: "video/*" }; var returnStatus = kony.phone.openMediaGallery(onSelectionCallback, querycontext); |
querycontext [Table] - Optional |
Query context is an Object that can be populated with key-value pairs for fine tuning the media items for display (currently only one key "mimetype" supported to query the gallery items ). The possible values of the mimetype key can be image/*, video/*, audio/*. This API returns the type of rawbytes that are obtained from onSelectionCallback of openMediaGallery. Rawbytes can be of different types such as image, audio, video, file, bytes, and livePhoto. This API is available from V8 SP3 onwards. var rawbytesType = rawbytes.getRawbytesType(); To check the obtained rawbyte type, the following constants can be used:
if(rawbytes.getRawbytesType() == constants. RAWBYTES_LIVEPHOTO) { // app logic } livePhotoResources - Rawbytes Property Returns both image and file paths, using this property you can get the both image and video paths. This property returns a json containing both video and image paths, and is available from V8 SP3 onwards. It contains the following keys:
var livePhotoResources = Rawbytes.livePhotoResources; //Example for creating Live photos using FFI |
PSP [Table] - Optional |
The PSP parameter is a dictionary with the following properties.
|
Example
openMediaGalleryForEmail: function() { kony.phone.openMediaGallery(this.openMediaGallaeryCallBck, { mimetype: "image/*" }); }
Return Values
None
Remarks
Android
From the Quantum Visualizer 202306 release, if the Target SDK API level of the app is set as 33, and the app uses the kony.phone.openMediaGallery API, you must enable support for granular media permissions.
To do so, navigate to Project Settings > Native > Android Mobile / Tablet, and add the following entries in the Permissions tab based on the type of media files you want to access:
- Enable the
READ_MEDIA_IMAGES
permission to access image files. - Enable the
READ_MEDIA_AUDIO
permission to access audio file. - Enable the
READ_MEDIA_VIDEO
permission to access video files.
iOS
Limitation: If you are using iOS 18 (or later) plugins, and you provide limited access to the photo library, the system provides full access to the app.
NOTE: If you provide the AlbumName key in the config of the img.writeToMediaGallery(config) method, the API implicitly reads all the existing album names (to create a new album, if the name does not match or to choose an existing one), therefore the API needs Full access to the photo library.
Exceptions
PhoneError
The following error codes are defined for Phone APIs
- 2100 - Unable to send the Message
- 2101 - Insufficient Permissions
- 2102 - Cannot open mail, mail not configured
- 2103 - Cannot open media gallery
Platform Availability
Supported on all platforms except Desktop Web.
This API provides various haptic feedback to users, and is available from V8 SP3 onwards.
Syntax
kony.phone.performHapticFeedback(hapticFeedbackValue);
Input Parameters
hapticFeedbackValue [constant] – Mandatory
Indicates the type of haptic feedback. Its possible values are as follows:
hapticFeedbackaValue | Description |
---|---|
0 - kony.hapticFeedback.SUCCESS | Triggers a haptic feedback for a successful event. |
1 - kony.hapticFeedback.WARNING | Triggers a haptic feedback that represents a warning to users. |
2 - kony.hapticFeedback.FAILURE | Triggers a haptic feedback for a failure event. |
3 - kony.hapticFeedback.LIGHT | Triggers a haptic feedback of light intensity. |
4 - kony.hapticFeedback.MEDIUM | Triggers a haptic feedback of medium intensity. |
5 - kony.hapticFeedback.HEAVY | Triggers a haptic feedback of high intensity. |
6 - kony.hapticFeedback.SELECTION | Triggers a haptic feedback that represents a selection/state change. |
Example
hapticFeedback: function(){ kony.phone.performHapticFeedback(5); }
Return Values
None
Remarks
- iOS
- The Haptic Feedback feature is available on iPhone 7 devices and later. These devices have Taptic Engine hardware and users can enable/disable Haptics from Device Settings-> Sounds & Haptics-> System Haptics.
- Android
- Users can enable the Vibrate on touch feature from Settings-> Sound & notification-> Other sounds.
Platform Availability
- iOS
This API either deletes a single event or a series of repeat events starting from the date specified in the eventHandle from the device calendar, depending on the provided removeOption parameter. While deleting a series of recurring events, the API deletes all subsequent events beginning from the date specified in the eventHandle; however, the API does not delete any repeat event that is before the specified date.
NOTE: To delete an event, you must first search for the event by using the findCalendarEvents API and delete the event.
Syntax
kony.phone.removeCalendarEvent(eventHandle, removeOption);
Input Parameters
Parameter | Description |
---|---|
eventHandle [Object] - Mandatory |
Event handle is returned by the find operation. |
removeOption - Optional |
This parameter is considered only for recurring events. If you do not specify a value for this parameter or pass an invalid value for a recurring event, the current event as well as future recurrences are deleted. Default fallback value of removeOption is constants.CALENDAREVENT_REMOVE_THIS_AND_FUTURE. You can fetch possible removeOption values for delete events by using the kony.phone.getRemoveEventOptions API. The following constants are available for removeOption:
|
Example
//To remove the calendar event from the device using 'kony.phone.removeCalendarEvent' API CalendarRemoveEvent: function() { if (this.startTime === "undefined" || this.startTime === undefined) { this.view.lblPhone.text = "Please create the calendar event."; return; } var evtobj = { type: "starting", start: this.startTime, finish: this.finishTime }; var events = kony.phone.findCalendarEvents(evtobj); kony.phone.removeCalendarEvent(events[0]); alert("Calendar event is removed. Please open device calendar to observe this"); }
kony.phone.removeCalendarEvent(events[1],constants.CALENDAREVENT_REMOVE_THIS);
kony.phone.removeCalendarEvent(events[1],constants.CALENDAREVENT_REMOVE_THIS_AND_FUTURE);
kony.phone.removeCalendarEvent(events[1]); //If it is non-recurring, the current event is deleted; however, if it is a recurring event, the event as well as future events will be deleted.
Return Values
None
Exceptions
PhoneError
The following error codes are defined for Phone APIs
- 2100 - Unable to send the Message
- 2101 - Insufficient Permissions
- 2102 - Cannot open mail, mail not configured
- 2103 - Cannot open media gallery
Error
- 100 – invalid type of parameters
- 101 – invalid number of arguments
- 102 – invalid input – thrown when the input is invalid based on the context.
- 103 – invalid operation – thrown when the operation is invalid based on the context.
- 104 – not supported error – thrown when the method is not supported at all.
- 105 – index out of range.
- 106 – unknown error.
Platform Availability
- iOS
- Android
Remarks
- READ_CALENDAR and WRITE_CALENDAR permissions are needed for this API.
- This API is supported for Android 4.0 version and above (that is, Android API level later to 13). Invocation on Android version less than 4.0 ( that is, Android API level earlier to 14) will be ignored.
- If this API removes last calendar event added to local calendar, then the local calendar account will be deleted.
When invoked, this API reads an SMS message received from the server. The API then retrieves the one-time password (OTP) from the message if it matches with the config provided.
Syntax
kony.phone.retrieveSMS(callback, SMSConfig);
Input Parameters
SMSConfig [Object] - Optional
SMSConfig supports the following key-value pairs:
Key | Description |
---|---|
OTPSizeLimit [Number] - Optional | Expected/desired size limit of the OTP. If the OTPSizeLimit is not specified, the default size limit is 6. |
OTPType [Constant] - Optional |
Expected/desired type of OTP. [ kony.phone.SMS_ALPHANUMERIC_OTP or kony.phone.SMS_NUMERIC_OTP] The default type is Numeric. |
OTPRegex [String] - Optional |
Customized regex to retrieve OTP or PIN as required. If customized regex is provided, all the other criteria such as OTPSizeLimit and OTPType are neglected. |
SMSListenerType [Constant] - Optional |
Type of SMS listener to be triggered. Following are the SMS listener types: kony.phone.SMS_WITHOUT_USER_CONSENT: Using this constant, OTP would be retrieved automatically without any user interaction. In this case, the message that you send from the server to the user's device must fulfill the following:
To generate a hash key, use any of the following ways:
Here is a sample message format: 123ABC78 FA+9qCX9VSu (123ABC78 is the one-time code and FA+9qCX9VSu is the hash string) kony.phone.SMS_WITH_USER_CONSENT: The User Consent Screen is displayed to users after the SMS with an OTP is received. The OTP would be retrieved only after user grants access to the SMS through the User Consent Screen. In this case, the message that you send from the server to the user's device must fulfill the following:
|
SMSSenderDetails [String] - Optional |
SMS sender details may be specified only if In this case, OTP will be retrieved only if the SMS was sent by that phone number specified in SMSSenderDetails key. The sender's phone number should be of E.164 format. |
callback [Function] - Mandatory
The callback executed to communicate the SMS Listener Registration status and response of API. The syntax of the callback function is:
callback(callbackObject)
The callbackObject contains SMS and status key value pairs.
SMS key: SMS object, the value of the SMS key is populated only when code is equal to kony.phone.SMS_RETRIEVED_SUCCESSFULLY. In case of any error, the SMS object is null.
The SMS object contains the following key-value pairs:
Key | Description |
---|---|
message [String] | SMS received |
OTP [String] | Retrieved OTP from SMS |
NOTE: The OTP value returned can be null/empty if the message doesn't contain any OTP matching the SMSConfig.
status key: Value of the status key contains the following key-value pairs:
Key | Description |
---|---|
code[Number] | status code |
message[String] | status message |
The code key can have any of the following values. A code value is populated when the scenario in the corresponding description occurs.
The following codes specify if the framework is successful in starting the SMS listener.
Code | Description |
---|---|
kony.phone.SMS_LISTENER_REGISTRATION_SUCCESS | SMS listener registered successfully. You must request the server for OTP only after the successful registration status is conveyed in a message callback. |
kony.phone.SMS_LISTENER_REGISTRATION_FAILED | SMS listener registration failed. |
The following codes are applicable only after kony.phone.SMS_LISTENER_REGISTRATION_SUCCESS is received.
Code | Description |
---|---|
kony.phone.SMS_RETRIEVED_SUCCESSFULLY | SMS retrieved successfully. |
kony.phone.SMS_TIMEOUT | The SMS listener has timed out as No SMS is received within 5mins of trigger of API. |
kony.phone.SMS_DEVELOPER_ERROR | Caller app has incorrect number of certificates. Only one certificate is allowed. This can occur only when SMSListenerType is set to kony.phone.SMS_WITHOUT_USER_CONSENT. |
kony.phone.SMS_ERROR | App-code collides with other installed apps. This can occur only when SMSListenerType is set to kony.phone.SMS_WITHOUT_USER_CONSENT. |
kony.phone.SMS_USER_CANCELLED | While SMSListenerType = kony.phone.SMS_WITH_USER_CONSENT, user denies OTP retrieval. This can occur only when SMSListenerType is set to kony.phone.SMS_WITH_USER_CONSENT. |
kony.phone.ACTIVITY_NOT_FOUND | While SMSListenerType = kony.phone.SMS_WITH_USER_CONSENT, an activity cannot be found to launch the Consent dialog. This can occur only when SMSListenerType is set to kony.phone.SMS_WITH_USER_CONSENT. |
kony.phone.SMS_UNKNOWN_ERROR | Any error with unknown root cause. |
NOTE: Ensure that you create an androidbuild.properties file in the project folder of your Quantum Visualizerworkspace, and add the following key: addSMSRetrieverSupport = UI
.
You can set the key to UI
or Non-UI
to fetch the required Gradle entries. To know more about adding Android properties to the androidbuild.properties file, click here.
Example
retrieveOTPFromSMS: function() { SMSConfig = {} SMSConfig.OTPSizeLimit = 4; SMSConfig.OTPType = kony.phone.SMS_NUMERIC_OTP; SMSConfig.SMSListenerType = kony.phone.SMS_WITH_USER_CONSENT; SMSConfig.SMSSenderDetails = null; try { kony.phone.retrieveSMS(callback, SMSConfig); } catch (err) { kony.print("ERROR:" + err); } function callback(callbackObj) { statusCode = callbackObj.status.code; kony.print("STATUS_CODE::" + statusCode); if (statusCode == kony.phone.SMS_LISTENER_REGISTRATION_SUCCESS) { //ADD CODE TO INDICATE SERVER TO SEND OTP } if (statusCode == kony.phone.SMS_RETRIEVED_SUCCESSFULLY) { kony.print("message:" + callbackObj.SMS.message) kony.print("otp:" + callbackObj.SMS.OTP) alert(callbackObj.SMS.OTP) } }
Return Values
None
Limitations
You must start an SMS retriever only after the previous registered retriever responds with a success or failure response. However, if you register a second SMS retriever before the first SMS retriever provides a response, the possible limitations are as follows:
- When two SMS retrievals without a user's consent run simultaneously, the SMS callbacks are triggered in the same sequence in which they are registered. This sequence might not be same as the sequence in which the user has sent the requests to the server. As a result, a mismatch in the provided OTP config might occur.
- When two SMS retrievals with a user's consent provide two unique sender details for two parallel SMS retrieval registrations, the SMS callbacks are triggered in the same sequence in which they are registered. The SMS details received at the native level does not contain the senders information. Consequently, a mismatch between the senders might occur.
Exceptions
Error Codes:
- 100 - Invalid number of arguments to API kony.phone.retrieveSMS()
- 101 - Invalid type of arguments to API kony.phone.retrieveSMS()
Platform Availability
- Android
This API provides access to the Messaging service of the underlying platform. You can send a text message to a specified number. This API accesses the messaging application of the underlying platform and uses that application to send text message to the specified number.
IMPORTANT: You can send only text messages and multimedia messages are not supported.
NOTE: When you send messages using this API, the charges as imposed by the Service Provider are applicable. On iPhone this API opens the Messages application with a prepopulated text and number.
You can use this API to send messages to other numbers without leaving the application.
Syntax
kony.phone.sendSMS(phonenumber, text);
Input Parameters
Parameter | Description |
---|---|
phonenumber [String] - Mandatory |
Number to which the SMS must be sent. |
text [String] - Mandatory |
Content of the SMS. |
Example
sendSMS: function() { if (kony.os.deviceInfo().model == "iPhone Simulator") { alert("Works only on device"); } else { var phoneNo = "+91 40 12345678"; // This is a dummy number var text = "Hi Kony developer"; kony.phone.sendSMS(phoneNo, text); } }
Return Values
None
Exceptions
PhoneError
The following error codes are defined for Phone APIs
- 2100 - Unable to send the Message.
- 2101 - Insufficient Permissions.
Remarks
When you send messages using this API, the messaging application of the underlying platform is used to send the message with the number and text you specified i.e., the phone number and the message are pre-populated in the messaging application.
Platform Availability
Available on all platforms except Desktop Web, Android Tablets, iPad.
NOTE: This API allows you to send only text messages. It does not support multimedia messages.
This API starts the vibration feature on a device, provided that device supports vibration. If the device does not support vibration, this API has no effect. If a vibration pattern is already in progress when this API is called, the previous pattern is halted and the new one begins. This API is available from V8 SP3 onwards.
IMPORTANT: For Android, you must define the VIBRATE permission under Manifest Properties.
<uses-permission android:name = "android.permission.VIBRATE" />
Syntax
kony.phone.startVibration (vibrationConfig, repeat);
Input Parameters
Parameter | Description |
---|---|
vibrationConfig [Array] - Mandatory |
Specifies the list of all vibration patterns as an array. Each vibration pattern object accepts the duration, amplitude, and delay keys. delay [Integer] - Mandatory Specifies that the vibration will be paused for the specified delay time in milliseconds. This parameter must be a positive number. The default value of delay is 0 milliseconds. Any invalid or negative values specified for delay reverts to the default value, i.e., 0 milliseconds. duration [Integer] – Mandatory The number of milliseconds for which the device vibrates. This parameter must be a positive number. The default value of duration is 0 milliseconds. Any invalid or negative values specified for duration reverts to the default value, i.e., 0 milliseconds. amplitude [Integer] - Optional Controls the strength of the vibration. This must be a value between 0 and 255.
For Android devices, when the vibration amplitude is 0, the vibration motor is turned off; whereas, when the vibration amplitude is 255, the vibration is performed at full strength. |
repeat [Boolean] – Optional | true : The repeat vibration pattern is repeated until the kony.phone.cancelVibration API is called. false : Stops the repeat vibration pattern. This is the default value. |
Example
//Device will vibrate for 100 milliseconds.
startVibration: function() { if(kony.phone.hasVibratorSupport()===true) { var vibrationConfig=[{ "delay": 0, "duration": 100, "amplitude": 250 }]; kony.phone.startVibration(vibrationConfig, true); } else{ alert("The device does not support vibration"); } }
Return Values
None
Behavior, Requirements, and Limitations
iOS
- The startVibration API generates only a single vibration effect.
- iOS does not support config parameters, such as amplitude and duration, for startVibration API.
- The startVibration API accepts arguments on iOS devices, but it ignores them. The API does not throw any error/exception.
Remarks
- You can call this API with or without arguments for Android. If the arguments are not specified, the device vibrates for 100 milliseconds to align with the behavior for iOS.
Platform Availability
- Android
- iOS