Other Components
- ActivityStarter
- BarcodeScanner
- BluetoothClient
- BluetoothServer
- Notifier
- SpeechRecognizer
- TextToSpeech
- TinyWebDB
- Web
ActivityStarter
A component that can launch another activity from your application.
You communicate with the activity starter by setting properties of the component to pass information related to the activity, including the action and activity class. See Using the Activity Starter Component for details and examples.
Activities that can be launched include:
- Starting another App Inventor for Android app. To do so, first determine
class of the other application by downloading the source code and using a
file explorer or unzip utility to find a file named
"youngandroidproject/project.properties". The first line of the file will start
with "main=" and be followed by the class name; for example,
main=com.gmail.Bitdiddle.Ben.HelloPurr.Screen1
To make your
ActivityStarter
launch this application, set the following properties:-
ActivityPackage
to the class name, dropping the last component (for example,com.gmail.Bitdiddle.Ben.HelloPurr
) -
ActivityClass
to the entire class name (for example,com.gmail.Bitdiddle.Ben.HelloPurr.Screen1
)
-
- Starting an activity that is built in to the Android OS, such as using the
camera, or performing a web search. You can start camera by setting the following
properties:
-
Action: android.intent.action.MAIN
-
ActivityPackage: com.android.camera
-
ActivityClass: com.android.camera.Camera
-
- Performing web search: Assuming the term you want to search for is "vampire"
(feel free to substitute your own choice), set the properties to:
-
Action: android.intent.action.WEB_SEARCH
-
ExtraKey: query
-
ExtraValue: vampire
-
ActivityPackage: com.google.android.providers.enhancedgooglesearch
-
ActivityClass: com.google.android.providers.enhancedgooglesearch.Launcher
-
- Opening a browser to a specified web page. Assuming the page you want to go to
is "www.facebook.com" (feel free to substitute your own choice), set the properties
to:
-
Action: android.intent.action.VIEW
-
DataUri: http://www.facebook.com
-
You can also launch third-party applications installed on the phone, provided you know the appropriate intents to invoke them, and you can also launch activities that produce text results and get them back to use in your application. The way this data is extracted depends on how the application has been implemented.
Properties
-
Action
: text - Action of the activity to be launched.
-
ActivityClass
: text - Class name of the activity to be launched.
-
ActivityPackage
: text - Package name of the activity to be launched.
-
DataUri
: text - URI passed to activity to be launched.
-
ExtraKey
: text - Key name of text passed to the activity.
-
ExtraValue
: text - Value of text passed to the activity.
-
Result
: text - Value returned by the activity being started.
-
ResultName
: text - The name used to extract the result returned from the activity being started.
-
ResultType
: text - Type information returned from the activity being started.
-
ResultUri
: text - URI (or Data) information returned from the activity being started.
Events
-
ActivityError(text message)
> - Indicates that an error occurred while using this ActivityStarter.
-
AfterActivity(text result)
- Called after activity ends.
Methods
-
text
ResolveActivity
() - Returns the name of the activity that corresponds to this ActivityStarter, or an empty string if no corresponding activity can be found. You can use this before starting an external application to ensure that the application is installed on the phone.
-
StartActivity()
- Start the activity associated with this component.
BarcodeScanner
This non-visible component uses the phone's camera to read a 1-dimensional barcode or 2-dimensional barcode (QR code). In order for this component to work, the Barcode scanner app from ZXing must be installed on the phone. This app is available for free in the Android Market.
Properties
-
Result
-
The text result of the last successful scan. This becomes available after
AfterScan
has been signaled. This value is also returned as theresult
value.
Methods
-
DoScan()
- Start a scan
Events
-
AfterScan(text result)
- Called after scanning ends.
BluetoothClient
Bluetooth client component
Properties
-
AddressesAndNames
- A list of the addresses and names of paired Bluetooth devices.
-
Available
- Tell whether Bluetooth is available on the Android device.
-
CharacterEncoding
- The character encoding to use when sending and receiving text.
-
DelimiterByte
- The delimiter byte to use when passing a negative number for the numberOfBytes parameter when calling ReceiveText, ReceiveSignedBytes, or ReceiveUnsignedBytes.
-
Enabled
- Tell whether Bluetooth is enabled.
-
HighByteFirst
- Whether 2 and 4 byte numbers should be sent and received with the high (or most significant) byte first. Check the documentation for the device with which your app will be communicating for the appropriate setting. This is also known as big-endian.
-
IsConnected
- Tell whether a Bluetooth connection has been made.
Events
noneMethods
-
number BytesAvailableToReceive()
- Returns an estimate of the number of bytes that can be received without blocking
-
boolean Connect(text address)
- Connect to the Bluetooth device with the specified address and the Serial Port Profile (SPP). Returns true if the connection was successful. The address parameter can contain extra characters after the MAC address if there is a space immediately after the MAC address. This means that you may pass an item from the list returned from the AddressesAndNames property without splitting apart the address and the name.
-
boolean ConnectWithUUID(text address, text uuid)
- Connect to the Bluetooth device with the specified address and UUID. Returns true if the connection was successful. The address parameter can contain extra characters after the MAC address if there is a space immediately after the MAC address. This means that you may pass an item from the list returned from the AddressesAndNames property without splitting apart the address and the name.
-
Disconnect()
- Disconnect from the connected Bluetooth device.
-
boolean IsDevicePaired(text address)
- Checks whether the Bluetooth device with the specified address is paired.
-
number ReceiveSigned1ByteNumber()
- Receive a signed 1-byte number from the connected Bluetooth device.
-
number ReceiveSigned2ByteNumber()
- Receive a signed 2-byte number from the connected Bluetooth device.
-
number ReceiveSigned4ByteNumber()
- Receive a signed 4-byte number from the connected Bluetooth device.
-
list ReceiveSignedBytes(number numberOfBytes)
- Receive multiple signed byte values from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
-
text ReceiveText(number numberOfBytes)
- Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
-
number ReceiveUnsigned1ByteNumber()
- Receive an unsigned 1-byte number from the connected Bluetooth device.
-
number ReceiveUnsigned2ByteNumber()
- Receive a unsigned 2-byte number from the connected Bluetooth device.
-
number ReceiveUnsigned4ByteNumber()
- Receive a unsigned 4-byte number from the connected Bluetooth device.
-
list ReceiveUnsignedBytes(number numberOfBytes)
- Receive multiple unsigned byte values from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
-
Send1ByteNumber(text number)
- Send a 1-byte number to the connected Bluetooth device.
-
Send2ByteNumber(text number)
- Send a 2-byte number to the connected Bluetooth device.
-
Send4ByteNumber(text number)
- Send a 4-byte number to the connected Bluetooth device.
-
SendBytes(list list)
- Send a list of byte values to the connected Bluetooth device.
-
SendText(text text)
- Send text to the connected Bluetooth device.
BluetoothServer
Bluetooth server component
Properties
-
Available: boolean
- Tell whether Bluetooth is available on the Android device.
-
CharacterEncoding: text
- The character encoding to use when sending and receiving text.
-
DelimiterByte: number
- The delimiter byte to use when passing a negative number for the numberOfBytes parameter when calling ReceiveText, ReceiveSignedBytes, or ReceiveUnsignedBytes.
-
Enabled: boolean
- Tell whether Bluetooth is enabled.
-
HighByteFirst: boolean
- Whether 2 and 4 byte numbers should be sent and received with the high (or most significant) byte first. Check the documentation for the device with which your app will be communicating for the appropriate setting. This is also known as big-endian.
-
IsAccepting: boolean
- Tell whether this BluetoothServer component is accepting an incoming connection.
-
IsConnected: boolean
- Tell whether a Bluetooth connection has been made.
Events
-
ConnectionAccepted()
- Indicates that a bluetooth connection has been accepted.
Methods
-
AcceptConnection(text serviceName)
- Accept an incoming connection with the Serial Port Profile (SPP).
-
AcceptConnectionWithUUID(text serviceName, text uuid)
- Accept an incoming connection with a specific UUID.
-
number BytesAvailableToReceive()
- Returns an estimate of the number of bytes that can be received without blocking
-
Disconnect()
- Disconnect from the connected Bluetooth device.
-
number ReceiveSigned1ByteNumber()
- Receive a signed 1-byte number from the connected Bluetooth device.
-
number ReceiveSigned2ByteNumber()
- Receive a signed 2-byte number from the connected Bluetooth device.
-
number ReceiveSigned4ByteNumber()
- Receive a signed 4-byte number from the connected Bluetooth device.
-
list ReceiveSignedBytes(number numberOfBytes)
- Receive multiple signed byte values from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
-
text ReceiveText(number numberOfBytes)
- Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
-
number ReceiveUnsigned1ByteNumber()
- Receive an unsigned 1-byte number from the connected Bluetooth device.
-
number ReceiveUnsigned2ByteNumber()
- Receive a unsigned 2-byte number from the connected Bluetooth device.
-
number ReceiveUnsigned4ByteNumber()
- Receive a unsigned 4-byte number from the connected Bluetooth device.
-
list ReceiveUnsignedBytes(number numberOfBytes)
- Receive multiple unsigned byte values from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
-
Send1ByteNumber(text number)
- Send a 1-byte number to the connected Bluetooth device.
-
Send2ByteNumber(text number)
- Send a 2-byte number to the connected Bluetooth device.
-
Send4ByteNumber(text number)
- Send a 4-byte number to the connected Bluetooth device.
-
SendBytes(list list)
- Send a list of byte values to the connected Bluetooth device.
-
SendText(text text)
- Send text to the connected Bluetooth device.
-
StopAccepting()
- Stop accepting an incoming connection.
Notifier
A notifier is a non-visible component that can show verious kinds of alerts and can log information. Use a notifier to display notices and alerts to users of your app, and also to log information that can help you debug your app.
Methods
-
ShowMessageDialog(Text message, Text title, Text buttonText)
- Pops up a notice that remains until the user taps a button with the given text. The arguments are the message to be shown, the title of the notice, and the label on the button.
-
ShowChooseDialog(Text message, Text title, Text button1Text, Text button2Text)
-
Pops up a notice the user must respond to by tapping one of two buttons with the
given text. The arguments are the message to be shown, the title of the notice,
and the labels on the left and right buttons, respectively. The
AfterChoosing
event is signalled after the user taps one of the buttons. -
ShowTextDialog(Text message, Text title)
-
Pops up a notice which the user must respond to by entering some text. The
arguments are the message to be shown and the title of the notice. The
AfterTextInput
event is signalled after the user enters the text. -
ShowAlert(Text message
- Pops up a temporary notice, which vanishes after a few seconds. The argument is the text of the notice.
-
LogError(Text message)
-
LogError(Text message)
-
LogError(Text message)
- These methods are for use in debugging. They write messages to the various logs on the Android device. The logs can be read with the use of Android debugging tools, like the Android Debug Bridge (ADB).
Events
-
AfterChoosing(Text choice)
-
Signaled after the user has made a choice in response to
ShowChooseDialog
. The argument is the text on the button that the user tapped. -
AfterTextInput(Text response)
-
Signaled after the user has responded to
ShowTextDialog
. The argument is the text on the button that the user entered.
SpeechRecognizer
Use a speech recognizer component to listen to the user speaking and convert the spoken sound into text using Android's speech recognition feature.
Properties
-
Result
- The last text produced by the recognizer.
Methods
-
GetText()
-
Asks the user to speak, and converts the speech to text. Signals the
AfterGettingText
event when the result is available.
Events
-
AfterGetting(Text result)
- Signaled after the recognizer has produced text. The argument is the text result that was produced.
-
BeforeGettingText()
- Signaled just before the recognizer is called.
TextToSpeech
Use a text-to-speech component to have the device speak text audibly.
In order for this component to work, the device must have the TTS Extended Service app by Eyes-Free Project installed. You can download this from http://code.google.com/p/eyes-free/downloads/list
The text-to-speech component has properties you can set to guide the pronunciation
of the text to be spoken. These properties use three-letter codes to specify the
language and the country in which the language is spoken. For example, you can
specify British English or US English. For British English, the language code is
eng
and the country code is GBR
, while for US English,
the language code is eng
and the country code is USA
. The
complete list is below.
Properties
-
Country
- The country code for speech production.
-
Language
- The language code for speech production.
-
Result
- Details to come.
Methods
-
Speak(Text message)
- Speaks the given text.
Events
-
AfterSpeaking(Text result)
- Signaled after the text is spoken. The argument is the text result that was produced.
-
BeforeSpeaking()
- Signaled just before the text is spoken.
Here are the language and country codes you can use. The codes are organized first by language; then, in each language section are a list of possible country codes:
- ces (Czech)
- CZE
-
- spa (Spanish)
- ESP
- USA
-
- deu (German)
- AUT
- BEL
- CHE
- DEU
- LIE
- LUX
-
- fra (French)
-
- BEL
- CAN
- CHE
- FRA
- LUX
-
- nld (Dutch)
- BEL
- NLD
-
- ita (Italian)
-
- CHE
- ITA
-
- pol (Polish)
-
- POL
-
- eng (English)
-
- AUS
- BEL
- BWA
- BLZ
- CAN
- GBR
- HKG
- IRL
- IND
- JAM
- MHL
- MLT
- NAM
- NZL
- PHL
- PAK
- SGP
- TTO
- USA
- VIR
- ZAF
- ZWE
TinyWebDB
Non-visible component that communicates with a Web service to store and retrieve information.
See Creating a Custom TinyWebDB Service.Properties
-
ServiceURL
Events
-
GotValue(text tagFromWebDB, any valueFromWebDB)
- Indicates that a GetValue server request has succeeded.
-
ValueStored()
- Event indicating that a StoreValue server request has succeeded.
-
WebServiceError(text message)
- Indicates that the communication with the Web service signaled an error
Methods
-
GetValue(text tag)
- GetValue asks the Web service to get the value stored under the given tag. It is up to the Web service what to return if there is no value stored under the tag. This component just accepts whatever is returned.
-
StoreValue(text tag, any valueToStore)
- Asks the Web service to store the given value under the given tag
Web
Non-visible component that provides functions for HTTP GET and POST requests.
Properties
-
AllowCookies
- Whether the cookies from a response should be saved and used in subsequent requests. Cookies are only supported on Android version 2.3 or greater.
-
RequestHeaders
- The request headers, as a list of two-element sublists. The first element of each sublist represents the request header field name. The second element of each sublist represents the request header field values, either a single value or a list containing multiple values.
-
ResponseFileName
- The name of the file where the response should be saved. If SaveResponse is true and ResponseFileName is empty, then a new file name will be generated.
-
SaveResponse
- Whether the response should be saved in a file.
-
Url
- The URL for the web request.
Events
-
GotFile(text url, number responseCode, text responseType, text fileName)
- Event indicating that a request has finished.
-
GotText(text url, number responseCode, text responseType, text responseContent)
- Event indicating that a request has finished.
Methods
-
text BuildPostData(list list)
- Converts a list of two-element sublists, representing name and value pairs, to a string formatted as application/x-www-form-urlencoded media type, suitable to pass to PostText.
-
ClearCookies()
- Clears all cookies for this Web component.
-
Get()
-
Performs an HTTP GET request using the Url property and retrieves the
response.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered. -
text HtmlTextDecode(text htmlText)
- Decodes the given HTML text value. HTML character entities such as &, <, >, ', and " are changed to &, <, >, ', and ". Entities such as &#xhhhh, and &#nnnn are changed to the appropriate characters.
-
text JsonTextDecode(text jsonText)
- Decodes the given JSON text value. If the given JSON text is surrounded by quotes, the quotes will be removed.
-
PostFile(text path)
-
Performs an HTTP POST request using the Url property and data from the specified
file.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered. -
PostText(text text)
-
Performs an HTTP POST request using the Url property and the specified text.
The characters of the text are encoded using UTF-8 encoding.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The responseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered. -
PostTextWithEncoding(text text, text encoding)
-
Performs an HTTP POST request using the Url property and the specified text.
The characters of the text are encoded using the given encoding.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered. -
text UriEncode(text text)
- Encodes the given text value so that it can be used in a URL.