Other Components

ActivityStarter
BarcodeScanner
Notifier
SpeechRecognizer
TextToSpeech
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
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 the result value.
Methods
DoScan()
Start a scan
Events
AfterScan(text result)
Called after scanning ends.
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

  • 最終更新:2010-12-22 01:49:22

このWIKIを編集するにはパスワード入力が必要です

認証パスワード