<h2>borg command</h2>

<h3>Name</h3>

<b>borg</b> - control and interact with the Android OS.

<h3>Synopsis</h3>

<tt>package require Borg</tt><br>
<tt>borg cmd ?<i>arg

<h3>Description</h3>

This command integrates the capabilities of Tcl/Tk with Android by way of several subcommands. These allow Tcl/Tk to go where it has never gone before by querying and controlling Bluetooth functionality, OS notifications (including device vibration and even speech), location information, etc.

<h4>Bluetooth-Related Commands</h4>

<tt>borg bluetooth devices</tt>

    Returns a list suited for <tt>array set</tt> or <tt>dict create</tt> commands containing the Bluetooth address and friendly name of all paired Bluetooth devices.

<tt>borg bluetooth state</tt>

    Returns the current Bluetooth state: <tt>off</tt>, <tt>on</tt>, <tt>turning_off</tt>, or <tt>turning_on</tt>.

<tt>borg bluetooth scanmode</tt>

    Returns the current Bluetooth scan mode: <tt>connectable</tt>, <tt>off</tt>, <tt>passive</tt>, or <tt>visible</tt>.

<tt>borg bluetooth myaddress</tt>

    Returns the Bluetooth address of the local default Bluetooth adapter.

<tt>borg bluetooth remoteaddress

    Returns the friendly name for the given Bluetooth

<tt>borg bluetooth on</tt>

    Quote from <a documentation</a>: do not use without explicit user action to turn on Bluetooth. Tries to turn the Bluetooth adapter on. Returns 1 if the adapter is already or going to be turned on, 0 otherwise.

<tt>borg bluetooth off</tt>

    Quote from <a documentation</a>: do not use without explicit user action to turn off Bluetooth. Tries to turn the Bluetooth adapter off. Returns 1 if the adapter is already or going to be turned off, 0 otherwise.

For communication over Bluetooth see the description of the [rfcomm command]. For handling of Bluetooth Low Energy (Bluetooth Smart) devices see the description of the [ble command].

<h4>USB-Related Commands</h4>

<tt>borg usbdevices

    If is omitted or false, a list suitable for the <tt>array set</tt> or <tt>dict create</tt> commands containing the USB device name and vendor/product identifier of all currently connected USB devices is returned. Otherwise, i.e. is true, three elements per USB device are returned: USB device name, product/vendor identifier, and USB interface information as in <tt>udev</tt>.

<tt>borg usbpermission <i>devname</i>

    Queries permission for the USB device and returns 1 if the device is usable, 0 if not, and a negative number on error. If the optional boolean argument is specified as true, a system dialog is shown allowing the user to grant or deny permission for the USB device.

For communication over USB serial converters see the description of the [usbserial command].

<h4>Network-Related Commands</h4>

<tt>borg networkinfo</tt>

    Returns the current state of the network: <tt>none</tt>, <tt>wifi</tt>, <tt>mobile gsm</tt>, etc. An update of this information is indicated by the <tt><<NetworkInfo>></tt> virtual event sent to all toplevel widgets.

<tt>borg tetherinfo</tt>

    Returns the current state of tethering as a list suited for <tt>array set</tt> or <tt>dict create</tt> with zero or three entries <tt>active</tt>, <tt>available</tt>, and <tt>error</tt> which usually contain interface names. An update of this information is indicated by the <tt><<TetherInfo>></tt> virtual event sent to all toplevel widgets.

<h4>Desktop-Related Commands</h4>

<tt>borg shortcut add <i>name-of-shortcut script-to-run</i>

    Adds an icon to the desktop, with the label specified. The script, specified as must use an absolute path as a URI and must be readable by the user id under which the AndroWish package has been registered by the Android installer. The last (optional) parameter allows the icon graphic to be specified. If not provided, a default AndroWish icon is used. According to the <a on iconography</a> icons should have an aspect ratio of 48 by 48 pixels (192 x 192 is recommended, at 4 times 48x48 pixels). Example (pseudo code):

<verbatim>
    package require base64
    proc read_binary_file {name} { # whatever is needed to read bytes ... }
    set icondata [read_binary_file
    set iconbase64 [::base64::encode -maxlen 0 $icondata]
    borg shortcut add "My App" $iconbase64
</verbatim>

<tt>borg shortcut delete

    Deletes an icon from desktop (depends on Android launcher support).

<h4>Notification-Related Commands</h4>

<tt>borg notification add <i>id title</i> ?<i>text icon action uri type categories component

    Adds a notification with and into the Android notification area. The integer specified by the caller, is used to identify the notification for later modification or deletion. The optional parameters starting from form an activity (see <tt>borg activity ...</tt>) to be carried out when the user clicks on the notification. See the description of <tt>borg alarm set</tt> below for special treatment of the parameter. The optional must be a PNG or JPG image encoded as base64 string. The size of the icon should be 24 by 24 pixels.

<tt>borg notification delete

    Deletes a notification identified that was created with the specified. If no is provided, all notifications are deleted.

<tt>borg notification led <i>id argb onms

    Adds a notification controlling the device LED. The integer specified by the caller, is used to identify the notification for later modification or deletion. The integer parameter <i>argb</i> is the LED color as combined RGB value with alpha channel, <i>onms</i> and <i>offms</i> are integers, too, controlling the duty cycle of blinking.

<tt>borg vibrate

    Turns the vibration motor on for integer milliseconds.

<tt>borg beep

    Plays a notification sound. If is specified and not an empty string, it is played as sound. If given as empty string, the current playback is stopped. If omitted or unable to be resolved, the default notification sound is played. The URI typically has the pattern where <tt>id</tt> is an integer number identifying a sound file. The <tt>borg content</tt> command can be used to obtain information on notification sounds from Android's media provider.

<tt>borg speak <i>text</i> ?<i>lang pitch

    Gets the Android to read out the string Optional parameter is the language code for the spoken language, e.g. en, en_US, de, es, etc. Optional parameters and control the voice and speed as float values. On success an integer number >= 1000 is returned which identifies the text to be spoken in various virtual events. On error a negative number is returned.
 <a information</a>.

<tt>borg stopspeak</tt>

    Stops speech output.

<tt>borg isspeaking</tt>

    Returns a small integer indicating the state of speech output. Zero indicates initialization of speech output has been performed but no speech output is currently active. One is returned when speech output is active. A small negative number indicates an error, temporary or permanent unavailability of the text-to-speech facility. In order to start up the text-to-speech facility this command can be used. The first call usually returns -1 and calls some few hundred milliseconds later return zero, indicating availability of the text-to-speech facility.

<tt>borg endspeak</tt>

    Stops speech output and releases system resources.

<tt>borg toast <i>text</i>

    Displays a text notification for a short period of time. The duration of that display is somewhat longer when is specified as true.

<tt>borg spinner on|off</tt>

    Displays or withdraws a spinner (rotating symbol indicating busy state) depending on argument.

<h4>Location-Related Commands</h4>

<tt>borg location start ?<i>minrate-in-ms</i>

    Begins acquiring location data via the Android OS (which may choose to use GPS, network info, etc.).

<tt>borg location stop</tt>

    Ends location data acquisition.

<tt>borg location get</tt>

    Returns the location data (as an <tt>array set</tt> or <tt>dict create</tt>form) where the key is the location source. Location updates trigger a virtual event <tt><<LocationUpdate>></tt> that is sent to all toplevel widgets. These toplevel event-handlers should, in turn, invoke <tt>borg location get</tt> to refresh their knowledge.

<tt>borg location gps</tt>

    Returns GPS information in <tt>array set</tt> or <tt>dict create</tt> form with the keys <tt>state</tt> (on or off) and <tt>first_fix</tt> (time in seconds until first fix expected). Updates in GPS information are indicated by the <tt><<GPSUpdate>></tt> virtual event sent to all toplevel widgets.

<tt>borg location satellites</tt>

    Returns GPS satellite information in <tt>array set</tt> or <tt>dict create</tt> form where the key is a numerical index and the values are per satellite information in <tt>array set</tt> or <tt>dict create</tt> form containing the fields <tt>index</tt>, <tt>azimuth</tt>, <tt>elevation</tt>, <tt>prn</tt>, <tt>snr</tt>, <tt>almanac</tt>, <tt>ephemeris</tt>, and <tt>infix</tt>. Updates in GPS information are indicated by the <tt><<GPSUpdate>></tt> virtual event sent to all toplevel widgets.

<tt>borg location nmea</tt>

    Returns a string made up of the NMEA sentences collected over the last second. Updates in this string are indicated by the <tt><<NMEAUpdate>></tt> virtual event sent to all toplevel widgets.

<h4>System-Related Commands</h4>

<tt>borg displaymetrics</tt>

    Returns information about the display in form suited for <tt>array set</tt> or <tt>dict create</tt>, e.g. display resolution, pixel density. The entry <tt>rotation</tt> gives the current screen rotation in degrees. The 0 degree point varies between devices, typical smart phones report 0 for portrait, tablets report 0 for landscape orientation. <a information</a>.

<tt>borg osbuildinfo</tt>

    Returns information about the operating system and device in form suited for <tt>array set</tt> or <tt>dict create</tt>, e.g. Android API level, version, device name, manufacturer etc. <a information</a>.

<tt>borg queryfeatures</tt>

    Returns information about features of the system (a lengthy list of strings) which is obtained from <a

<tt>borg queryconsts

    Returns a dictionary of constants of the (loaded) Java class The keys are the names of the constants, the values their value. For example, the symbols of <tt>SYSTEM_UI_*</tt> flags are available when you evaluate:

<verbatim>
    borg queryconsts android.view.View
</verbatim>

<tt>borg queryfields

    Returns a dictionary of constants and static fields of the (loaded) Java class This is similar to <tt>borg queryconsts</tt> but allows to retrieve no-constant strings, too. Most useful in combination with the <a class.

<tt>borg packageinfo

    Returns information about installed packages or an individual package if its is given. In the first case, a list with package names is returned, in the latter case a list of key value pairs with package information which can be used for <tt>array set</tt> or <tt>dict create</tt>.

<tt>borg providerinfo</tt>

    Returns the authority names of all content providers known to the system as a list.

<tt>borg log <i>prio tag

    Writes the message to Android's system log with priority (one of <tt>verbose</tt>, <tt>debug</tt>, <tt>info</tt>, <tt>warn</tt>, <tt>error</tt>, or <tt>fatal</tt>) and a user chosen prefix These log messages can be displayed using <tt>adb logcat</tt> on the development system.

<tt>borg trace <i>message

    Evaluates and adds before and after that evaluation to Android's system trace buffer. This is supported only on newer Android OS versions (4.3 and above) and further described in the <a class.

<tt>borg systemproperties

    Returns a list of system properties (a lengthy list of key value pairs) or the value of a specific system property if is given.

<tt>borg checkpermission

    Returns true or false depending on manifest permission For a detailed list see the description of the <a class.

<h4>Sensor-Related Commands</h4>

<tt>borg sensor list</tt>

    Returns a list of the available sensors of the device. Each item is suited for <tt>array set</tt> or <tt>dict create</tt> and contains the fields <tt>index</tt> (integer index of the sensor, used to identify it), <tt>type</tt> (sensor type, one of <tt>accelerometer</tt>, <tt>temperature</tt>, <tt>game_rotation_vector</tt>, <tt>geomagnetic_rotation_vector</tt>, <tt>gravity</tt>, <tt>gyroscope</tt>, <tt>gyroscope_uncalibrated</tt>, <tt>light</tt>, <tt>linear_acceleration</tt>, <tt>magnetic_field</tt>, <tt>magnetic_field_uncalibrated</tt>, <tt>orientation</tt>, <tt>pressure</tt>, <tt>proximity</tt>, <tt>relative_humidity</tt>, <tt>rotation_vector</tt>, <tt>step_counter</tt>, and <tt>step_detector</tt>), <tt>mindelay</tt> (minimum update interval in milliseconds), <tt>maxrange</tt> (maximum range, floating point), <tt>resolution</tt> (floating point), <tt>power</tt> (in mA, floating point), and <tt>name</tt> (name of the sensor). <a information</a>.

<tt>borg sensor enable|disable|state

    Turns the sensor identified by on or off, or returns its state (0=off, 1=on). An enabled sensor generates <tt><<SensorUpdate>></tt> virtual events which are sent to toplevel windows. These events are either periodic updates or change notifications depending on the kind of sensor and its refresh rate. If a sensor is not read out using <tt>borg sensor get ...</tt> for a certain amount of time that sensor is automatically disabled to conserve battery power. If the application enters background (see virtual event <tt><<WillEnterBackground>></tt>) all enabled sensors are disabled and re-enabled again when the application comes back to foreground (see virtual event <tt><<WillEnterForeground>></tt>).

<tt>borg sensor get

    Returns the last value acquired from the sensor identified by as a list suited for <tt>array set</tt> or <tt>dict create</tt> containing the fields <tt>index</tt> (integer), <tt>enabled</tt> (sensor state, 0 or 1), <tt>maxrange</tt> (see above), <tt>resolution</tt> (see above), <tt>accuracy</tt> (the accuracy of this value), <tt>values</tt> (the sensor value, zero or more floating point numbers). When both <tt>accelerometer</tt> and <tt>magnetic_field</tt> sensors are turned on, the information for the <tt>magnetic_field</tt> sensor has two additional entries <tt>orientation</tt> (3 element list of azimuth, pitch, roll) and <tt>inclination</tt>. The <tt>pressure</tt> sensor has an additional entry <tt>altitude</tt> (meters above sea level). <a information</a>.

<h4>Android Content (shared databases)</h4>

<tt>borg content query <i>uri</i> ?<i>columns</i> ?<i>where</i> ?<i>whereargs</i>

    Performs a query on an Android content provider given by and returns a cursor token (a Tcl command which deals with that cursor). The optional are a list of database columns to appear in the result set, e.g.

<verbatim>
    set cursor [borg content query {display_name _id}]
</verbatim>

    where an empty list of database columns works like the SQL statement "SELECT *".

    The optional and parameters form the SQL WHERE clause of the query. Question mark parameter markers in are positionally substituted by the information from the list. If the parameter does not use a question mark parameter marker, an empty parameter string is obligatory as in

<verbatim>
    set cursor [borg content query {} "_id=810" {}]
</verbatim>

    which is equivalent to

<verbatim>
    set cursor [borg content query {} "_id=?" 810]
</verbatim>

    The optional forms the SQL ORDERBY part of the query.

    Here's another example demonstrating how data is retrieved:

<verbatim>
    set cursor [borg content query
    # initially, cursor points before first row
    while {[$cursor move 1]} {
        puts [$cursor getrow]
    }
</verbatim>

<tt>borg content delete <i>uri selection</i> ?<i>value

    Deletes rows from an Android content provider given by and returns the number of deleted rows. forms the SQL WHERE clause of the deletion where question mark parameter markers are substituted by Example:

<verbatim>
    borg content delete name=? my_item
</verbatim>

<tt>borg content insert <i>uri key value

    Inserts a row into an Android content provider given by and returns another URI which identifies the inserted row. and are pairs of column name and column value for the SQL INSERT operation. Example:

<verbatim>
    borg content insert name my_item value "Some value"
    ->
</verbatim>

<tt>borg content update <i>uri values</i> ?<i>selection</i>

    Updates zero or more rows of an Android content provider given by and returns the number of updated rows. is a list made up of a sequence of column names and column values. is the optional SQL WHERE clause with question mark parameter markers. The parameter markers are substituted by the values from Example:

<verbatim>
    # system settings wants the name in the URI
    borg content update {value {New Value}}
</verbatim>

<h4>Cursors from Android Content queries</h4>

When a <tt>borg content</tt> query returned a cursor token, this token is a Tcl command to deal with the query's result set:

<tt>$cursor close</tt>

    Finishes the query and deletes the Tcl command.

<tt>$cursor columnnames</tt>

    Returns a list of column names of the result set.

<tt>$cursor count</tt>

    Returns the number of rows of the result set.

<tt>$cursor getblob

    Returns the column (zero-based) of the current row of the result set as a base64 encoded string.

<tt>$cursor getdouble

    Returns the column (zero-based) of the current row of the result set as a floating point number.

<tt>$cursor getint

    Returns the column (zero-based) of the current row of the result set as a integer number.

<tt>$cursor getpos</tt>

    Returns the index of the current row (zero-based).

<tt>$cursor getrow</tt>

    Returns the current row as a Tcl list made up of column names and values, like <tt>{name1 value1 name2 value2}</tt> in the order specified by the cursor's constructor. Blobs from the result set are converted into base64 encoded strings.

<tt>$cursor getstring

    Returns the column (zero-based) of the current row of the result set as a string.

<tt>$cursor isnull

    Returns true when the column (zero-based) of the current row of the result set is an SQL NULL value.

<tt>$cursor move

    Relative move of the current row index. Negative <i>pos</i> goes backward.

<tt>$cursor moveto

    Absolute move of the current row index.

<h4>Speech Recognition</h4>

<tt>borg speechrecognition intent <i>args

    Use the speech recognition service. is a parameter list to control the speech recognition (<a information</a>). is invoked when the speech recognition is complete. That procedure receives the parameters <tt>retcode</tt> and <tt>data</tt> as in the callback for <tt>borg activity</tt>. <tt>data</tt> is a list of key value pairs suited for <tt>array set</tt> or <tt>dict create</tt>.

<tt>borg speechrecognition callback

    Establishes as global callback procedure receiving speech recognition events as described by the RecognitionListener interface (<a information</a>). That procedure receives the parameters <tt>retcode</tt> and <tt>data</tt> as in the callback for <tt>borg activity</tt>. <tt>data</tt> is a list of key value pairs suited for <tt>array set</tt> or <tt>dict create</tt>. There are up to two special keys present in data: <tt>type</tt> giving the event type (one of <tt>result</tt>, <tt>partialresult</tt>, <tt>ready</tt>, <tt>event</tt>. <tt>rms</tt>, <tt>end</tt>, <tt>begin</tt>) and <tt>value</tt> giving numeric values for certain event types (error code for <tt>error</tt>, audio level for <tt>rms</tt>).

<tt>borg speechrecognition start

    Starts the speech recognition. For see the description in <tt>borg speechrecognition intent ....</tt>.

<tt>borg speechrecognition cancel</tt>

    Immediately cancels the speech recognition. No further events are reported through the global callback procedure.

<tt>borg speechrecognition stop</tt>

    Stops the speech recognition. Events can be still reported through the global callback procedure.

<h4>Telephone-Related Commands</h4>

<tt>borg phoneinfo</tt>

    Returns information about the current state of the telephone as a list suited for <tt>array set</tt> or <tt>dict create</tt>. This information is only available when the application manifest has the <tt>android.permission.READ_PHONE_STATE</tt> permission (which is left out in current [AndroWish] releases). For further information see the Android documentation on the classes
<a
<a and
<a

<tt>borg sendsms phonenumber msg ?<i>action_send action_delivered

    Sends an SMS text message to The optional arguments and are the action names of broadcast intents which are generated on state changes regarding the SMS message and can be captured by a broadcast listener callback (see <tt>borg broadcast register</tt> et.al.). The optional argument is the SMS message center. The command returns 1 on successful start of the send operation, 0 otherwise. It is only available when the application manifest has the <tt>android.permission.SEND_SMS</tt> permission (which is left out in current [AndroWish] releases). For further information see the Android documentation on the class
<a

<h4>Broadcast</h4>

<tt>borg broadcast list

    Returns a list of all registered broadcast handlers in the interpreter when is omitted. Otherwise it returns the command to be invoked when the broadcast is received.

<tt>borg broadcast register <i>action</i>

    Registers the command to be invoked when the broadcast is received.

<tt>borg broadcast unregister

    Unregisters the command bound to the reception of the broadcast

<tt>borg broadcast send <i>action</i> ?<i>uri type categories

    Sends the broadcast with the optional properties/arguments and For the optional items see the description in <tt>borg activity</tt>.

<h4>Locale</h4>

<tt>borg locale ?default?</tt>

    Returns information about the current default locale of the JVM. The result is in a form suitable for <tt>array set</tt> or <tt>dict get</tt> and contains the fields <tt>country</tt>, <tt>display_country</tt>, <tt>display_language</tt>, <tt>display_name</tt>, <tt>display_variant</tt>, <tt>iso3_country</tt>, <tt>iso3_language</tt>, <tt>language</tt>, and <tt>variant</tt>.

<tt>borg locale

    Returns information about the locale identified by which must be specified as a two letter code with an optional variant and an optional encoding part, e.g. <tt>de</tt>, <tt>fr_BE</tt>, or <tt>en_GB.UTF-8</tt>.

<tt>borg locale tts</tt>

    Returns information about the locale used for text-to-speech. If text-to-speech facilities weren't used when the command is invoked, the returned information is identical with <tt>borg locale default</tt>.

<tt>borg locale set

    Changes the current locale of the JVM to the language code If the locale change succeeded, the environment variable <tt>env(LANG)</tt> is changed accordingly.

<h4>Camera-Related Commands</h4>

Camera support is available on devices with Android 3.0 or newer.

<tt>borg camera close</tt>

    Close the camera. Returns non-zero on success, zero otherwise, e.g. when the camera was already closed.

<tt>borg camera current</tt>

    Returns the currently opened camera number or -1 when the camera is not opened. On many tablets camera 0 is the back-facing camera, and camera 1 the front-facing one.

<tt>borg camera grayimage
<tt>borg camera greyimage

    Copies the most recent camera preview as grey image into the photo image identified by Returns non-zero on success or zero if no data transfer has taken place. If is omitted, a four element list is returned with the first element being the image width, the second the image height, the third the number of bytes per pixel, and the last the image's grey values with 1 byte per pixel as a byte array. In this case an error is indicated by throwing an exception. An experimental feature is direct rendering into a widget. In this case the parameter must be the path name of a Tk window which should be a frame or toplevel widget. When the camera is started the background color of the widget should be set to an empty string so that no drawing calls from Tk are carried out. When the camera is stopped, it should be set to black.

<tt>borg camera image

    Copies the most recent camera preview as color image into the photo image identified by Returns non-zero on success or zero if no data transfer has taken place. If is omitted, a four element list is returned with the first element being the image width, the second the image height, the third the number of bytes per pixel, and the last the image's RGB values with 3 bytes per pixel in red, green, blue order as a byte array. In this case an error is indicated by throwing an exception.
An experimental feature is direct rendering into a widget. In this case the parameter must be the path name of a Tk window which should be a frame or toplevel widget. When the camera is started the background color of the widget should be set to an empty string so that no drawing calls from Tk are carried out. When the camera is stopped, it should be set to black.

<tt>borg camera info</tt>

    Returns information about the currently opened camera as a two element list made up of integer numbers. The first is the rotation of the camera relative to the screen, the second an indication for front-facing (1) or back-facing (0) view of the camera relative to the screen. If no camera is opened the result is an empty list.

<tt>borg camera jpeg</tt>

    Returns a JPEG image of the camera as a byte array after preview has been started using <tt>borg camera start</tt> and JPEG capture has been initiated with <tt>borg camera takejpeg</tt>. In contrast to <tt>borg camera image ...</tt> this command consumes the image. If no JPEG picture is available when the command is invoked, an error is thrown.

<tt>borg camera mirror ?<i>x

    Controls mirroring of preview images which are mirrored along the X axis when is one and along the Y axis when is one. <tt>borg camera mirror 0 1</tt> is useful to mirror the preview image of a front-facing camera.

<tt>borg camera numcameras</tt>

    Returns the number of available cameras.

<tt>borg camera open

    Opens camera number and returns non-zero on success. Only one camera can be opened at any one time. On error or when a camera is already opened, zero is returned. When is omitted the first camera is opened (usually the back-facing if two cameras are available).

<tt>borg camera orientation

    Returns the current orientation of the preview image relative to the screen or changes it to

<tt>borg camera parameters ?<i>key value

    Returns or changes camera parameters given as key-value pairs, e.g. <tt>preview-size 320x240</tt> will change the size of preview images to width 320 and height 240. The command returns the current camera parameters (after the potential change, when keys and values where given) as a key-value list which can be processed with <tt>array set</tt> or <tt>dict get</tt>.

<tt>borg camera start</tt>

    Starts the camera. Acquired preview images are reported by the virtual event <tt><<ImageCapture>></tt>. Returns non-zero on success, zero when the camera is already started or an error has been detected. When the acquisition of camera preview images is running <tt>borg camera image</tt> or <tt>borg camera greyimage</tt> must be invoked within 5 seconds, otherwise image acquisition is automatically stopped and needs to be restarted with another <tt>borg camera start</tt> command.

<tt>borg camera state</tt>

    Returns the current camera state as string: <tt>unknown</tt>, <tt>closed</tt>, <tt>stopped</tt>, or <tt>capture</tt>.

<tt>borg camera stop</tt>

    Stops the camera, i.e. no more images are acquired. Returns non-zero on success, zero when the camera is already stopped or an error has been detected.

<tt>borg camera takejpeg</tt>

    Requests the camera to take a JPEG image. It is required that the camera is capturing, i.e. <tt>borg camera start</tt> has been called already. The point in time when acquisition of the JPEG image starts is indicated by the virtual event <tt><<Shutter>></tt>. When the JPEG image is ready for processing the virtual event <tt><<PictureTaken>></tt> is sent. The command returns a non-zero value when JPEG capture is in progress, zero on error.

<h4>NFC Related</h4>

Many devices have hardware support for NFC (Near Field Communication) tags. In order to deal with such items, a callback command for the broadcast <tt>tk.tcl.wish.nfc</tt> must be registered. The callback's arguments contain information on the NFC tag in these keys:

<tt>android.nfc.extra.ID</tt>

    The the base64 encoded ID of the tag.

<tt>android.nfc.extra.TAG</tt>

    The underlying/supported technologies of the tag as a string. Currently only <tt>android.nfc.tech.Ndef</tt> and <tt>android.nfc.tech.NdefFormatable</tt> are detected and handled.

<tt>android.nfc.extra.NDEF_MESSAGES</tt>

    If present contains the NDEF formatted information contained in the tag encoded in base64.

The last read tag ID is remembered and can be dealt with using these <tt>borg</tt> subcommands:

<tt>borg ndefread <i>tagid</i>

    Returns the current or NDEF formatted information contained in the tag given as base64 encoded string.

<tt>borg ndefwrite <i>tagid

    Writes the NDEF formatted information (one or more NDEF records) in which must be base64 encoded into the tag given

<tt>borg ndefformat <i>tagid

    Formats an empty tag and like <tt>borg ndefwrite</tt> writes NDEF formatted information into the tag. An unformatted tag can be detected in the <tt>tk.tcl.wish.nfc</tt> callback procedure by inspecting the technology information: The string <tt>android.nfc.tech.Ndef</tt> is absent but the string <tt>android.nfc.tech.NdefFormatable</tt> is present.

<h4>OS Environment</h4>

Information provided by the <a class.

<tt>borg osenvironment datadir</tt>

    Return the user data directory (see <a

<tt>borg osenvironment downloadcachedir</tt>

    Return the download/cache content directory (see <a

<tt>borg osenvironment externalstoragedir</tt>

    Return the primary shared/external storage directory (see <a

<tt>borg osenvironment externalstoragepublicdir

    Get a top-level shared/external storage directory for placing files of a particular type (see <a The parameter can be obtained by using information returned from <tt>borg queryfields android.os.Environment</tt>.

<tt>borg osenvironment externalstoragestate</tt>

    Returns the current state of the primary shared/external storage media (see <a

<tt>borg osenvironment isexternalstorageemulated</tt>

    Returns whether the primary shared/external storage media is emulated (see <a

<tt>borg osenvironment isexternalstorageremovable</tt>

    Returns whether the primary shared/external storage media is physically removable (see <a

<tt>borg osenvironment rootdir</tt>

    Return root of the "system" partition holding the core Android OS (see <a

<h4>Shared Preferences</h4>

An interface to <a is provided using the <tt>borg sharedpreferences</tt> subcommand. This allows to load/store typed values of an application in a key-value store which does not require extra file permissions.

<tt>borg sharedpreferences <i>file</i> getboolean <i>key

    Return a boolean value (using if not present) from the shared preference file identified by stored under the name

<tt>borg sharedpreferences <i>file</i> getfloat <i>key

    Return a floating point value (using if not present) from the shared preference file identified by stored under the name

<tt>borg sharedpreferences <i>file</i> getint <i>key

    Return an integer value (using if not present) from the shared preference file identified by stored under the name

<tt>borg sharedpreferences <i>file</i> getlong <i>key

    Return a 64 bit integer value (using if not present) from the shared preference file identified by stored under the name

<tt>borg sharedpreferences <i>file</i> getstring <i>key

    Return a string value (using if not present) from the shared preference file identified by stored under the name

<tt>borg sharedpreferences <i>file</i> setboolean <i>key

    Store the boolean into the shared preference file identified by under the name

<tt>borg sharedpreferences <i>file</i> setfloat <i>key

    Store the floating point into the shared preference file identified by under the name

<tt>borg sharedpreferences <i>file</i> setint <i>key

    Store the integer into the shared preference file identified by under the name

<tt>borg sharedpreferences <i>file</i> setlong <i>key

    Store the 64 bit integer into the shared preference file identified by under the name

<tt>borg sharedpreferences <i>file</i> setstring <i>key

    Store the string into the shared preference file identified by under the name

<tt>borg sharedpreferences <i>file</i> remove

    Remove the value stored under the name from the shared preference file identified by

<tt>borg sharedpreferences <i>file</i> clear</tt>

    Remove all key-value pairs stored in the shared preference file identified by

<tt>borg sharedpreferences <i>file</i> all</tt>

    Return a Tcl list suitable for <tt>array set</tt> of all key-value pairs from the shared preference file identified by

<tt>borg sharedpreferences <i>file</i> alltypes</tt>

    Return a Tcl list suitable for <tt>array set</tt> of all keys and their respective value types from the shared preference file identified by

<tt>borg sharedpreferences <i>file</i> keys</tt>

    Return a Tcl list of all keys from the shared preference file identified by

<h4>General</h4>

<tt>borg withdraw</tt>

    Hides the application window by putting it to the end of Android's activity stack. Can be useful when bound to the Back key (<tt><Key-Break></tt> in AndroWish). There's no opposite command, i.e. the application can be brought to front again only by user interaction.

<tt>borg brightness

    Sets or gets the screen brightness. If the percentage is negative, the default value is restored.

<tt>borg onintent

    Sets or gets the callback which is evaluated when the application received an Android intent. When evaluating that command, the parameters action name, URI, MIME type, categories, arguments from the intent are appended. When the callback is set for the first time, it gets immediately evaluated with the parameters of the current (startup) intent.

<tt>borg queryactivites <i>action</i> ?<i>uri type categories

    Queries Android's activity manager for activities on the given intent parameters. and are optional lists. The latter when non-empty must contain the two elements package name and class name.

<tt>borg queryservices <i>action</i> ?<i>uri type categories

    Queries Android's activity manager for services on the given intent parameters, similar to <tt>borg queryactivities</tt>.

<tt>borg querybroadcastreceivers <i>action</i> ?<i>uri type categories

    Queries Android's activity manager for broadcast receivers on the given intent parameters, similar to <tt>borg queryactivities</tt>.

<tt>borg screenorientation

    Queries or switches the screen orientation, can be one of <tt>unspecified</tt>, <tt>landscape</tt>, <tt>portrait</tt>, <tt>user</tt>, <tt>behind</tt>, <tt>sensor</tt>, <tt>nosensor</tt>, <tt>sensorlandscape</tt>, <tt>sensorportrait</tt>, <tt>reverselandscape</tt>, <tt>reverseportrait</tt>, <tt>fullsensor</tt>, <tt>userlandscape</tt>, <tt>userportrait</tt>, <tt>fulluser</tt>, or <tt>locked</tt>.

<tt>borg keyboardinfo</tt>

    Returns information about the current keyboard configuration as a list suited for <tt>array set</tt> or <tt>dict create</tt> with these fields: <tt>keyboard</tt> with possible values <tt>none</tt>, <tt>12key</tt>, and <tt>qwerty</tt>, <tt>hidden</tt> and <tt>hard_hidden</tt> with values 0 (not hidden), 1, (hidden), and -1 (unknown). This can be read out any time. An update in keyboard configuration state is indicated by the virtual event <tt><<KeyboardInfo>></tt>.

<tt>borg alarm clear <i>action</i> ?<i>uri type categories

    Clears an alarm whose pattern matches the given intent parameters.

<tt>borg alarm set <i>when repeat action</i> ?<i>uri type categories component arg

    Sets an alarm to fire at (UN*X epoch, seconds) with repetition each seconds, when is greater than 0. The alarm sends an intent made up of the given intent parameters etc.). The parameter is interpreted specially: when empty no component is set on the intent, when given as self the calling package/class is set as component for the intent (sending the intent to itself, i.e. the callback of <tt>borg onintent</tt> will receive it). In all other cases component must be a list with the two elements package name and class name. and following parameters are added to the intent as key value pairs of extra data.

<tt>borg alarm wakeup <i>when repeat action</i> ?<i>uri type categories component arg

    Like <tt>borg alarm set</tt> but this type of alarm is able to wake up the device when suspended (device behavior depends on lock screen settings).

<tt>borg activity <i>action uri type</i> ?<i>categories</i> ?<i>component</i> ?<i>arguments</i>

    This a very flexible command that allows extensive access to the Android OS and other applications. and are optional lists. is the name of the procedure that is evaluated when the activity is complete. are key-value pairs where the values are mapped to Java strings by default. If the key is a 2-element list made up of a data type indicator (<tt>int</tt>, <tt>byte</tt>, <tt>short</tt>, <tt>char</tt>, <tt>long</tt>, <tt>float</tt>, <tt>double</tt>, <tt>Uri</tt>) followed by the key, the value is converted to that data type. See below for some examples of this command.

<tt>borg systemui

    Returns or sets various flags to control certain aspects of system UI elements displayed on the device's screen. This is currently supported only on Android 4.4 and newer versions. See the documentation on <a for a description of the <tt>SYSTEM_UI_*</tt> flags.

<h3>Events</h3>

These events are generated for/by certain <tt>borg</tt> related commands. They are reported to toplevel widgets only.

<tt><<LocationUpdate>></tt>

    Location information has been updated and can be read out using <tt>borg location get</tt>.

<tt><<GPSUpdate>></tt>

    GPS related information has been updated and can be read out using <tt>borg location gps</tt> and <tt>borg location satellites</tt>.

<tt><<NMEAUpdate>></tt>

    NMEA data has been updated and can be read out using <tt>borg location nmea</tt>.

<tt><<NetworkInfo>></tt>

    Network state has changed and can be read out using <tt>borg networkinfo</tt>.


<tt><<TetherInfo>></tt>

    Tethering state has changed and can be read out using <tt>borg tetherinfo</tt>.

<tt><<Bluetooth>></tt>

    A change in Bluetooth state and/or scan mode has occured and can be read out using <tt>borg bluetooth state</tt> and/or <tt>borg bluetooth scanmode</tt>.

<tt><<SensorUpdate>></tt>

    A sensor can be read using <tt>borg sensor get ...</tt>. The field <tt>%x</tt> identifies the sensor.

<tt><<KeyboardInfo>></tt>

    The keyboard configuration did change and can be obtained by <tt>borg keyboardinfo</tt>.

<tt><<PhoneCallState>></tt>

    The call state of the telephone has changed and can be obtained by <tt>borg phoneinfo</tt>.

<tt><<PhoneDataActivity>></tt>

    The state of the telephone's data state has changed and can be obtained by <tt>borg phoneinfo</tt>.

<tt><<PhoneConnectionState>></tt>

    The state of the telephone's connectivity has changed and can be obtained by <tt>borg phoneinfo</tt>.

<tt><<PhoneServiceState>></tt>

    The service state of the telephone has changed and can be obtained by <tt>borg phoneinfo</tt>.

<tt><<PhoneSignalStrength>></tt>

    The signal quality of the telephone has changed and can be obtained by <tt>borg phoneinfo</tt>.

<tt><<ImageCapture>></tt>

    A preview camera image is ready and can be obtained by <tt>borg camera image or <tt>borg camera greyimage The field <tt>%x</tt> represents the camera capture state (true when preview images are captured, false when capture will be stopped).

<tt><<Shutter>></tt>

    The camera is about to take a JPEG image.

<tt><<PictureTaken>></tt>

    The camera has taken a JPEG picture which can be obtained and consumed by <tt>borg camera jpeg</tt>. When the event is reported, image capture of preview images is automatically stopped.

<tt><<USBAttached>></tt>

    A USB device was attached. To find out information about the device, use the <tt>borg usbdevices</tt> command. This event is generated on Android 4.4 and newer.

<tt><<USBDetached>></tt>

    An USB device was detached (opposite of <tt><<USBAttached>></tt>).

<tt><<TTSInit>></tt>

    The text-to-speech facility has been started up or shut down. The %x substitution gives an indication for startup (=0), error (=-1), and unavailability (<-1). Supported in Android 4.1 and higher.

<tt><<TTSStart>></tt>

    Speech output of a string has started. The %x substitution is equal to the integer returned by the corresponding <tt>borg speak</tt> command. Supported in Android 4.1 and higher.

<tt><<TTSError>></tt>

    Error indication for a string to be spoken by <tt>borg speak</tt>. The %x substitution is equal to the integer returned by the corresponding <tt>borg speak</tt> command as for the <tt><<TTSStart>></tt> event. Supported in Android 4.1 and higher.

<tt><<TTSDone>></tt>

    End of speech indication for a string to be spoken.  The %x substitution is equal to the integer returned by the corresponding <tt>borg speak</tt> command as for the <tt><<TTSStart>></tt> event. Supported in Android 4.1 and higher.

<h3><tt>borg activity</tt> Examples</h3>

Sample code to open a browser on the Tcl'ers wiki:

<verbatim>
    borg activity android.intent.action.VIEW text/html
</verbatim>

Sample code to launch the "wifi settings" page:

<verbatim>
borg activity android.settings.WIFI_SETTINGS {} {} {} {} {}
</verbatim>

Sample code to capture an image (only makes thumbnails):

<verbatim>
    proc callback {retcode action uri mimetype categories data} {
        if {$retcode == -1} {
            # SUCCESS
            array set result $data
            if {[info exists result(data)]} {
                myphoto configure -data $result(data)
            }
        }
    }
    package require Img
    image create photo myphoto
    borg activity android.media.action.IMAGE_CAPTURE {} {} {} {} {} callback
</verbatim>

Sample code to capture an image, which makes full size images but requires a file on external storage:

<verbatim>
    proc callback {filename retcode action uri mimetype categories data} {
        if {$retcode == -1} {
            # SUCCESS
            myphoto configure -file $filename
            catch {file delete -force $filename}
        }
    }
    package require Img
    image create photo myphoto
    set filename [file join $env(EXTERNAL_FILES) myphoto.jpeg]
    borg activity android.media.action.IMAGE_CAPTURE {} {} {} {} \
       [list {Uri output} [list callback $filename]
</verbatim>

Reading barcodes using the <a barcode scanner</a> (which needs to be be installed on your device):

<verbatim>
    proc barcode_read {code action uri type cat data} {
        array set result $data
        if {[info exists result(SCAN_RESULT)]} {
            # that is the barcode
            # result(SCAN_RESULT_FORMAT) is the barcode format
        }
    }

    borg activity com.google.zxing.client.android.SCAN {} {} {} {} {} barcode_read
</verbatim>