📅  最后修改于: 2020-12-07 04:59:44             🧑  作者: Mango
SL4A基于外观设计模式,可与基础Android API进行通信。本章介绍了立面设计模式和各种SL4A API立面的工作方式。
外观是提供接口的对象,该接口简化了对应用程序中相关接口的访问。换句话说,立面将库与客户端的工作隔离开来,并充当每个子系统级别的入口。因此,客户只能通过其外观进行通信。下图对此进行了解释。
SL4A会为其支持的每种语言提供口译员。解释器通过称为façade的接口访问底层的Android API。
下表列出了顶层外观及其提供的功能-
S.No. | Android API Facade & Description |
---|---|
1 |
ActivityResultFacade It sets how your script will return information as an activity. This method implies that your script will return a result of some kind. The result type can be set to either RESULT_CANCELED(0) or RESULT_OK(-1) |
2 |
AndroidFacade It provides access to common Android functions like reading input, notifications, launching application components etc. |
3 |
ApplicationManagerFacade List all available and running packages, launch an activity, create your task manager or terminate a specific set of packages. |
4 |
BatteryManagerFacade Exposes the battery manager and allows tracking battery status, health, type level, voltage etc. |
5 |
BluetoothFacade Provides access to Bluetooth capabilities from basic connection features to sending and receiving both ASCII and binary data. This façade requires at least API level 5. |
6 |
CameraFacade This method provides access to all camera-related functions. Allows taking a picture using the device’s camera and saving it to a specified path. It provides two functions namely cameraCapturePicture and cameraInteractiveCapturePicture. These functions are strictly for using the lens on the rear of the device. |
7 |
CommonIntentsFacade Provides access to common Android Intents like opening a list of contacts, making a map search, starting an activity by action etc. |
8 |
ContactsFacade Allows access to contacts such as providing the contact list for picking a contact, querying the contact list by attributes and getting a list of all contacts with their IDs and attributes. Some methods provided by the façade include contactsGet, pickContact, contactsGetById etc. |
9 |
EventFacade The Android OS maintains an event queue for passing information between applications asynchronously. This façade provides functions to manage the event queue such as clearing the existing events, posting new events, listing, registering and unregistering broadcast signals etc. Examples of methods include eventPost, eventClearBuffer, etc. |
10 |
EyesFreeFacade Available on devices below API level 4. It allows scripts to speak using text-to-speech technology. This façade is now replaced by TextToSpeechFacade. The only available function is ttsSpeak. |
11 |
LocationFacade Provides functions that enables tracking the current location either by GPS or by using information about the cell tower you’re currently using. This feature requires an active internet connection to do the actual lookup. The façade provides methods like getLastKnownLocation, startLocating, stopLocating, readLocation etc. |
12 |
MediaPlayerFacade Allows playing media files, controlling the media player, querying the current status of the media player and getting information about the media files. mediaIsPlaying, mediaPlayInfo and mediaPlayList returns the current state of the media player. A call to the startActivity function launches the media player. Functions like mediaPlay, mediaPlayPause, mediaPlayClose, mediaPlaySeek,mediaPlayStart and mediaPlaySetLooping are used to control the media player. |
13 |
MediaRecorderFacade This façade provides audio and video recording capability. startInteractiveVideoRecording, recorderStartMicrophone, recorderCaptureVideo functions are used to launch and start audio/video recording respectively. To end a previously started recording call the recorderStop function. |
14 |
PhoneFacade Makes available basic phone operations like tracking phone state, roaming status, initiating calls, SIM information etc. programmatically. Examples of methods include phoneCallNumber, phoneDialNumber, getCellLocation etc. |
15 |
PreferencesFacade Allows access to shared preferences like getting the list of existing preferences and reading, modifying and adding new preferences. There are three functions supported by SL4A r4 release: prefGetAll, prefGetValue and prefPutValue. |
16 |
SensorManagerFacade Allows tracking sensor data such as light,acceleration, magnetic field and orientation. To start/ stop sensing use the startSensing (deprecated and replaced with startSensingThreshold and startSensingTimed by SL4r4) and stopSensing function calls. readSensors, sensorsGetLight, sensorsReadAccelerometer, sensorsReadMagnetometer and sensorsReadOrientation are the functions provided by this façade. |
17 |
SettingsFacade Provides access to different phone settings like ringer volume, screen brightness, airplane mode, vibration, media volume etc. Functions provided by this façade are checkAirplaneMode, checkRingersilentMode and checkScreenOn(atleast API level 7), getVibrateMode, setScreenTimeout, toggleVibrateMode setRingerVolume etc. |
18 |
SignalStrengthFacade Allows monitoring phone signal strength. Call the startTrackingSignalStrengths function to start gathering data. Call the readSignalStrengths function to start gathering data. To shut down the process call the stoptrackingSignalStrengths function. It requires at least API level 7. |
19 |
SmsFacade It has functions for deleting, reading, marking and sending SMS messages. Examples of functions provided by this façade include smsMarkMessageRead, smsDeleteMessage, smsSend etc. |
20 |
SpeechRecognitionFacade Enables adding speech recognition functionality to the script. It has only one function named recognizeSpeech. |
21 |
TextToSpeechFacade Provides TTS services for API4 and later. To have a device speak use the ttsSpeak function. To determine if the speak function has completed use the ttsIsSpeaking function. |
22 |
ToneGeneratorFacade Generates DTMF tones for given digits. To use it you must call the generateDtmfTones function. |
23 |
UiFacade Provides functions for creating user interface elements like textboxes, checkboxes, datepickers etc. It also allows interactive use of HTML pages. |
24 |
WakeLockFacade Provides functions to create a wake lock include wakeLockAcquireBright, wakeLockAcquireDim, wakeLockAcquireFull and wakelockAcquirePartial. |
25 |
WebCamFacade This façade requires at least API level 8. It allows streaming MJPEG streams from the front-facing device camera to the network. To start/stop the webcam use the webcamStart and the webcamStop functions respectively. To adjust the quality of the video while streaming use the webcamAdjustQuality function. |
26 |
WifiFacade Helps you to control the Wi-Fi radio on your device. It allows scripts to query the status of Wi-Fi connectivity, search for access points, connect to and disconnect WiFi networks and hold a Wi-Fi lock during script execution. |
有关这些外观提供的方法的完整列表,请参见https://code.google.com 。接下来的章节说明了如何使用AndroidFaçadeAPI函数创建实用程序。