Artifact Content
Not logged in

Artifact 7cdb12e2d08dfd2a8b1c7d5186d354716920ed96:

Wiki page [Android facilities] by chw 2020-08-15 17:58:40.
D 2020-08-15T17:58:40.860
L Android\sfacilities
P 0025df0ae53d039d467acec4ef4ca37c2ed1d135
U chw
W 52900
<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 ...</i>?</tt>

<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 <i>address</i></tt>

    Returns the friendly name for the given Bluetooth <tt><i>address</i></tt>.

<tt>borg bluetooth on</tt>

    Quote from <a href="http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#enable()">Android 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 href="http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#disable()">Android 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 ?<i>extended</i>?</tt>

    If <tt><i>extended</i></tt> 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. <tt><i>extended</i></tt> 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> ?<i>ask</i>?</tt>

    Queries permission for the USB device <tt><i>devname</i></tt> and returns 1 if the device is usable, 0 if not, and a negative number on error. If the optional boolean argument <tt><i>ask</i></tt> 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> ?<i>png-icon-as-base-64-string</i>?</tt>

    Adds an icon to the desktop, with the label <tt><i>name-of-shortcut</i></tt> specified. The script, specified as <tt><i>script-to-run</i></tt> must use an absolute path as a <tt>file://</tt> 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 <tt><i>png-icon-as-base-64-string</i></tt> allows the icon graphic to be specified. If not provided, a default AndroWish icon is used. According to the <a href="http://developer.android.com/design/style/iconography.html">guidelines 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 "/mnt/sdcard/appicon_48_48.png"]
    set iconbase64 [::base64::encode -maxlen 0 $icondata]
    borg shortcut add "My App" file://mnt/sdcard/speaktest.tcl $iconbase64
</verbatim>

<tt>borg shortcut delete <i>name-of-shortcut</i></tt>

    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 arguments</i>?</tt>

    Adds a notification with <tt><i>title</i></tt> and <tt><i>text</i></tt> into the Android notification area. The integer <tt><i>id</i></tt>, specified by the caller, is used to identify the notification for later modification or deletion. The optional parameters starting from <tt><i>action</i></tt> 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 <tt><i>component</i></tt> parameter. The optional <tt><i>icon</i></tt> 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 ?<i>id</i>?</tt>

    Deletes a notification identified that was created with the <tt><i>id</i></tt> specified. If no <tt><i>id</i></tt> is provided, all notifications are deleted.

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

    Adds a notification controlling the device LED. The integer <tt><i>id</i></tt>, 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 <i>ms</i></tt>

    Turns the vibration motor on for integer <tt><i>ms</i></tt> milliseconds.

<tt>borg beep ?<i>uri</i>?</tt>

    Plays a notification sound. If <tt><i>uri</i></tt> is specified and not an empty string, it is played as notification/ringtone/alarm 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 <tt>content://media/{internal,external}/audio/media/&lt;id&gt;</tt>, 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 rate</i>?</tt>

    Gets the Android to read out the string <tt><i>text</i></tt>. Optional parameter <tt><i>lang</i></tt> is the language code for the spoken language, e.g. en, en_US, de, es, etc. Optional parameters <tt><i>pitch</i></tt> and <tt><i>rate</i></tt> 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 href="http://developer.android.com/reference/android/speech/tts/TextToSpeech.html">More 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> ?<i>flag</i>?</tt>

    Displays a text notification <tt><i>text</i></tt> for a short period of time. The duration of that display is somewhat longer when <tt><i>flag</i></tt> 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> ?<i>min-dist-in-m</i>??</tt>

    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 href="http://developer.android.com/reference/android/util/DisplayMetrics.html">More 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 href="http://developer.android.com/reference/android/os/Build.html">More information</a>.

<tt>borg queryfeatures</tt>

    Returns information about features of the system (a lengthy list of strings) which is obtained from <a href="http://developer.android.com/reference/android/content/pm/PackageManager.html#getSystemAvailableFeatures()">getSystemAvailableFeatures</a>.

<tt>borg queryconsts <i>classname</i></tt>

    Returns a dictionary of constants of the (loaded) Java class <tt><i>classname</i></tt>. 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 <i>classname</i></tt>

    Returns a dictionary of constants and static fields of the (loaded) Java class <tt><i>classname</i></tt>. This is similar to <tt>borg queryconsts</tt> but allows to retrieve no-constant strings, too. Most useful in combination with the <a href="http://developer.android.com/reference/android/os/Environment.html">android.os.Environment</a> class.

<tt>borg packageinfo ?<i>name</i>?</tt>

    Returns information about installed packages or an individual package if its <tt><i>name</i></tt> 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 message</i></tt>

    Writes the message <tt><i>message</i></tt> to Android's system log with priority <tt><i>prio</i></tt> (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 <tt><i>tag</i></tt>. These log messages can be displayed using <tt>adb logcat</tt> on the development system.

<tt>borg trace <i>message script</i></tt>

    Evaluates <tt><i>script</i></tt> and adds <tt><i>message</i></tt> 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 href="http://developer.android.com/reference/android/os/Trace.html">android.os.Trace</a> class.

<tt>borg systemproperties ?<i>name</i>?</tt>

    Returns a list of system properties (a lengthy list of key value pairs) or the value of a specific system property if <tt><i>name</i></tt> is given.

<tt>borg checkpermission <i>name</i></tt>

    Returns true or false depending on manifest permission <tt><i>name</i></tt>. For a detailed list see the description of the <a href="http://developer.android.com/reference/android/Manifest.permission.html">android.Manifest.permission</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 href="http://developer.android.com/reference/android/hardware/Sensor.html">More information</a>.

<tt>borg sensor enable|disable|state <i>index</i></tt>

    Turns the sensor identified by <tt><i>index</i></tt> 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 <i>index</i></tt>

    Returns the last value acquired from the sensor identified by <tt><i>index</i></tt> 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 href="http://developer.android.com/reference/android/hardware/SensorEvent.html">More information</a>.

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

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

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

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

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

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

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

    which is equivalent to

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

    The optional <tt><i>orderby</i></tt> forms the SQL ORDERBY part of the query.

    Here's another example demonstrating how data is retrieved:

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

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

    Deletes rows from an Android content provider given by <tt><i>uri</i></tt> and returns the number of deleted rows. <tt><i>selection</i></tt> forms the SQL WHERE clause of the deletion where question mark parameter markers are substituted by <tt><i>value</i></tt>. Example:

<verbatim>
    borg content delete content://settings/system name=? my_item
</verbatim>

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

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

<verbatim>
    borg content insert content://settings/system name my_item value "Some value"
    -> content://settings/system/4711
</verbatim>

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

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

<verbatim>
    # system settings wants the name in the URI
    borg content update content://settings/system/my_item {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 <i>index</i></tt>

    Returns the <tt><i>index</i></tt>th column (zero-based) of the current row of the result set as a base64 encoded string.

<tt>$cursor getdouble <i>index</i></tt>

    Returns the <tt><i>index</i></tt>th column (zero-based) of the current row of the result set as a floating point number.

<tt>$cursor getint <i>index</i></tt>

    Returns the <tt><i>index</i></tt>th 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 <i>index</i></tt>

    Returns the <tt><i>index</i></tt>th column (zero-based) of the current row of the result set as a string.

<tt>$cursor isnull <i>index</i></tt>

    Returns true when the <tt><i>index</i></tt>th column (zero-based) of the current row of the result set is an SQL NULL value.

<tt>$cursor move <i>pos</i></tt>

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

<tt>$cursor moveto <i>pos</i></tt>

    Absolute move of the current row index.

<h4>Speech Recognition</h4>

<tt>borg speechrecognition intent <i>args cmd</i></tt>

    Use the speech recognition service. <tt><i>args</i></tt> is a parameter list to control the speech recognition (<a href="http://developer.android.com/reference/android/speech/RecognizerIntent.html">more information</a>). <tt><i>cmd</i></tt> 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 <i>cmd</i></tt>

    Establishes <tt><i>cmd</i></tt> as global callback procedure receiving speech recognition events as described by the RecognitionListener interface (<a href="http://developer.android.com/reference/android/speech/RecognitionListener.html">more 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 <i>args</i></tt>

    Starts the speech recognition. For <tt><i>args</i></tt> 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 href="http://developer.android.com/reference/android/telephony/TelephonyManager.html">TelephonyManager</a>,
<a href="http://developer.android.com/reference/android/telephony/PhoneStateListener.html">PhoneStateListener</a>, and
<a href="http://developer.android.com/reference/android/telephony/SignalStrength.html">SignalStrength</a>.

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

    Sends an SMS text message <tt><i>msg</i></tt> to <tt><i>phonenumber</i></tt>. The optional arguments <tt><i>action_send</i></tt> and <tt><i>action_delivered</i></tt> 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 <tt><i>smsc</i></tt> 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 href="http://developer.android.com/reference/android/telephony/SmsManager.html">SmsManager</a>.

<h4>Broadcast</h4>

<tt>borg broadcast list ?<i>action</i>?</tt>

    Returns a list of all registered broadcast handlers in the interpreter when <tt><i>action</i></tt> is omitted. Otherwise it returns the command to be invoked when the broadcast <tt><i>action</i></tt> is received.

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

    Registers the command <tt><i>cmd</i></tt> to be invoked when the broadcast <tt><i>action</i></tt> is received.

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

    Unregisters the command bound to the reception of the broadcast <tt><i>action</i></tt>.

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

    Sends the broadcast <tt><i>action</i></tt> with the optional properties/arguments <tt><i>uri</i></tt>, <tt><i>type</i></tt>, <tt><i>categories</i></tt>, and <tt><i>arguments</i></tt>. 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 <i>lang</i></tt>

    Returns information about the locale identified by <tt><i>lang</i></tt>, 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 <i>lang</i></tt>

    Changes the current locale of the JVM to the language code <tt><i>lang</i></tt>. 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 ?<i>photo</i>?</tt><br>
<tt>borg camera greyimage ?<i>photo</i>?</tt>

    Copies the most recent camera preview as grey image into the photo image identified by <tt><i>photo</i></tt>. Returns non-zero on success or zero if no data transfer has taken place. If <tt><i>photo</i></tt> 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 <tt><i>photo</i></tt> 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 ?<i>photo</i>?</tt>

    Copies the most recent camera preview as color image into the photo image identified by <tt><i>photo</i></tt>. Returns non-zero on success or zero if no data transfer has taken place. If <tt><i>photo</i></tt> 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 <tt><i>photo</i></tt> 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 y</i>?</tt>

    Controls mirroring of preview images which are mirrored along the X axis when <tt><i>x</i></tt> is one and along the Y axis when <tt><i>y</i></tt> 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 ?<i>num</i>?</tt>

    Opens camera number <tt><i>num</i></tt> 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 <tt><i>num</i></tt> is omitted the first camera is opened (usually the back-facing if two cameras are available).

<tt>borg camera orientation ?<i>degrees</i>?</tt>

    Returns the current orientation of the preview image relative to the screen or changes it to <tt><i>degrees</i></tt>.

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

    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> ?<i>cached</i>?</tt>

    Returns the current or <tt><i>cached</i></tt> NDEF formatted information contained in the tag given <tt><i>tagid</i></tt> as base64 encoded string.

<tt>borg ndefwrite <i>tagid ndefmsg</i></tt>

    Writes the NDEF formatted information (one or more NDEF records) in <tt><i>ndefmsg</i></tt> which must be base64 encoded into the tag given <tt><i>tagid</i></tt>.

<tt>borg ndefformat <i>tagid ndefmsg</i></tt>

    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 href="http://developer.android.com/reference/android/os/Environment.html">android.os.Environment</a> class.

<tt>borg osenvironment datadir</tt>

    Return the user data directory (see <a href="http://developer.android.com/reference/android/os/Environment.html#getDataDirectory()">getDataDirectory</a>).

<tt>borg osenvironment downloadcachedir</tt>

    Return the download/cache content directory (see <a href="http://developer.android.com/reference/android/os/Environment.html#getDownloadCacheDirectory()">getDownloadCacheDirectory</a>).

<tt>borg osenvironment externalstoragedir</tt>

    Return the primary shared/external storage directory (see <a href="http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()">getExternalStorageDirectory</a>).

<tt>borg osenvironment externalstoragepublicdir ?<i>type</i>?</tt>

    Get a top-level shared/external storage directory for placing files of a particular type (see <a href="http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)">getExternalStoragePublicDirectory</a>). The parameter <tt><i>type</i></tt> 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 href="http://developer.android.com/reference/android/os/Environment.html#getExternalStorageState()">getExternalStorageState</a>).

<tt>borg osenvironment isexternalstorageemulated</tt>

    Returns whether the primary shared/external storage media is emulated (see <a href="http://developer.android.com/reference/android/os/Environment.html#isExternalStorageEmulated()">isExternalStorageEmulated</a>).

<tt>borg osenvironment isexternalstorageremovable</tt>

    Returns whether the primary shared/external storage media is physically removable (see <a href="http://developer.android.com/reference/android/os/Environment.html#isExternalStorageRemovable()">isExternalStorageRemovable</a>).
 
<tt>borg osenvironment rootdir</tt>

    Return root of the "system" partition holding the core Android OS (see <a href="http://developer.android.com/reference/android/os/Environment.html#getRootDirectory()">getRootDirectory</a>).

<h4>Shared Preferences</h4>

An interface to <a href="https://developer.android.com/reference/android/content/SharedPreferences.html">android.content.SharedPreferences</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 default</i></tt>

    Return a boolean value (using <tt><i>default</i></tt> if not present) from the shared preference file identified by <tt><i>file</i></tt> stored under the name <tt><i>key</i></tt>.

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

    Return a floating point value (using <tt><i>default</i></tt> if not present) from the shared preference file identified by <tt><i>file</i></tt> stored under the name <tt><i>key</i></tt>.

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

    Return an integer value (using <tt><i>default</i></tt> if not present) from the shared preference file identified by <tt><i>file</i></tt> stored under the name <tt><i>key</i></tt>.

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

    Return a 64 bit integer value (using <tt><i>default</i></tt> if not present) from the shared preference file identified by <tt><i>file</i></tt> stored under the name <tt><i>key</i></tt>.

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

    Return a string value (using <tt><i>default</i></tt> if not present) from the shared preference file identified by <tt><i>file</i></tt> stored under the name <tt><i>key</i></tt>.

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

    Store the boolean <tt><i>value</i></tt> into the shared preference file identified by <tt><i>file</i></tt> under the name <tt><i>key</i></tt>.

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

    Store the floating point <tt><i>value</i></tt> into the shared preference file identified by <tt><i>file</i></tt> under the name <tt><i>key</i></tt>.

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

    Store the integer <tt><i>value</i></tt> into the shared preference file identified by <tt><i>file</i></tt> under the name <tt><i>key</i></tt>.

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

    Store the 64 bit integer <tt><i>value</i></tt> into the shared preference file identified by <tt><i>file</i></tt> under the name <tt><i>key</i></tt>.

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

    Store the string <tt><i>value</i></tt> into the shared preference file identified by <tt><i>file</i></tt> under the name <tt><i>key</i></tt>.

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

    Remove the value stored under the name <tt><i>key</i></tt> from the shared preference file identified by <tt><i>file</i></tt>.

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

    Remove all key-value pairs stored in the shared preference file identified by <tt><i>file</i></tt>.

<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><i>file</i></tt>.

<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><i>file</i></tt>.

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

    Return a Tcl list of all keys from the shared preference file identified by <tt><i>file</i></tt>.

<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 ?<i>percent</i>?</tt>

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

<tt>borg onintent ?<i>command</i>?</tt>

    Sets or gets the callback <tt><i>command</i></tt> 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 component</i>?</tt>

    Queries Android's activity manager for activities on the given intent parameters. <tt><i>categories</i></tt> and <tt><i>component</i></tt> 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 component</i>?</tt>

    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 component</i>?</tt>

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

<tt>borg screenorientation ?<i>orient</i>?</tt>

    Queries or switches the screen orientation, <tt><i>orient</i></tt> 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 component</i>?</tt>

    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 ...</i>?</tt>

    Sets an alarm to fire at <tt><i>when</i></tt> (UN*X epoch, seconds) with repetition each <tt><i>repeat</i></tt> seconds, when <tt><i>repeat</i></tt> is greater than 0. The alarm sends an intent made up of the given intent parameters (<tt><i>action</i></tt> etc.). The <tt><i>component</i></tt> 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. <tt><i>arg</i></tt> 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 ...</i>?</tt>

    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> ?<i>callback</i>????</tt>

    This a very flexible command that allows extensive access to the Android OS and other applications. <tt><i>categories</i></tt>, <tt><i>component</i></tt>, and <tt><i>arguments</i></tt> are optional lists. <tt><i>callback</i></tt> is the name of the procedure that is evaluated when the activity <tt><i>action</i></tt> is complete. <tt><i>arguments</i></tt> 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 ?<i>flags</i>?</tt>

    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 href="http://developer.android.com/reference/android/view/View.html">android.view.View</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 <i>photo</i></tt> or <tt>borg camera greyimage <i>photo</i></tt>. 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 http://wiki.tcl.tk 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} file://$filename] [list callback $filename]
</verbatim>

Reading barcodes using the <a href="http://code.google.com/p/zxing">ZXing 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>
Z d2145e6984d299e1ad4591ffa7320252