Utils
The Utils object provides useful utility functions and properties.
Supported Platform(s)
| - BlackBerry OS 5.0+ |
| - BlackBerry PlayBook 1.0+ |
| - Ripple Emulator |
| API | BB5.0 | BB6.0 | BB7.0 | PB1.0 | PB2.0 | BB10 | Ripple |
|---|---|---|---|---|---|---|---|
| blackberry.utils.blobToString | Y | Y | Y | Y | Y | Y | |
| blackberry.utils.documentToBlob | Y | ||||||
| blackberry.utils.generateUniqueId | Y | Y | Y | Y | Y | Y | |
| blackberry.utils.parseURL | Y | Y | Y | Y | Y | Y | |
| blackberry.utils.stringToBlob | Y | Y | Y | Y | Y | Y |
Configuration Document Settings
|
To use all of the API described for this object, you must ensure the following settings are in your configuration document: |
|
You must declare the feature element(s) below in your configuration document: |
| Feature ID | BB5.0 | BB6.0 | BB7.0 | PB1.0 | PB2.0 | BB10 | Ripple |
|---|---|---|---|---|---|---|---|
| <feature id="blackberry.utils" /> | Y | Y | Y | Y | Y | Y |
| Permission Elements (PlayBook and BlackBerry 10+) |
|---|
| This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application. |
Functions
** Marked for Deprecation
Functions
static
String
blackberry.utils.blobToString
(blob : Blob, [encoding : String])
Construct a new String by converting the blob using the specified character encoding
| Supported Platforms | |
|---|---|
| - BlackBerry OS 5.0+ | |
| - BlackBerry PlayBook 1.0+ | |
| - Ripple Emulator | |
| Parameters | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| blob |
The Blob object to be converted. The acceptable blob size is documented below:
|
||||||||||||
| encoding | [Default Value: ISO-8859-1] The name of a supported character encoding.BlackBerry supports the following character encodings: ISO-8859-1, UTF-8, UTF-16BE, US-ASCII. Besides these encodings, Web API also supports BASE64 encoding. Support of other encodings depends on the configuration of the BlackBerry Smartphone. | ||||||||||||
Return:
The String result from converting the Blob
Code Example:
|
static
Blob
blackberry.utils.documentToBlob
(doc : Document)
Deprecation Notice:
This API is deprecated, please use blackberry.utils.stringToBlob instead.For example:
var foo = blackberry.utils.stringToBlob( document.toString() );
Convert a document into a Blob. Supported in 5.0.0 only.
| Supported Platforms | |
|---|---|
| - BlackBerry OS 5.0 | |
| Parameters | |
|---|---|
| doc | The document to be converted. |
Return:
The Blob result from converting the Document
static
Number
blackberry.utils.generateUniqueId
()
This method will generate a unique number.
| Supported Platforms | |
|---|---|
| - BlackBerry OS 5.0+ | |
| - BlackBerry PlayBook 1.0+ | |
| - Ripple Emulator | |
Return:
A unique number from JavaScript's Math.random() function.
Code Example:
|
static
blackberry.utils.URL
blackberry.utils.parseURL
(url : String)
Parses a URL string and returns an URL object.
| Supported Platforms | |
|---|---|
| - BlackBerry OS 5.0+ | |
| - BlackBerry PlayBook 1.0+ | |
| - Ripple Emulator | |
| Parameters | |
|---|---|
| url | The URL string to be parsed. |
Return:
A blackberry.utils.URL object is returned if the parsing is successful.
Code Example:
|
static
Blob
blackberry.utils.stringToBlob
(str : String, [encoding : String])
Convert a string object into a Blob using the specified character encoding.
| Supported Platforms | |
|---|---|
| - BlackBerry OS 5.0+ | |
| - BlackBerry PlayBook 1.0+ | |
| - Ripple Emulator | |
| Parameters | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| str |
The string to be converted. The acceptable string length is documented below:
|
||||||||||||
| encoding | [Default Value: ISO-8859-1] The name of a supported character encoding.BlackBerry supports the following character encodings: ISO-8859-1, UTF-8, UTF-16BE, US-ASCII. Besides these encodings, Web API also supports BASE64 encoding. Support of other encodings depends on the configuration of the BlackBerry Smartphone. | ||||||||||||
Return:
The Blob result from converting the String
Code Example:
|