- SL4A - Packaging & Distributing
- SL4A - Background Script with Python
- SL4A - Utilities using Python Facades
- SL4A - Building GUIs
- SL4A - Exploring Android API
- SL4A - Working with Eclipse
- SL4A - Navigating the Android SDK
- SL4A - Configuring Your Device
- SL4A - Development Environment
- SL4A - Python Library
- SL4A - Architecture
- SL4A - Scripting Layer for Android
- SL4A - Android Architecture
- SL4A - Android Overview
- SL4A - Home
SL4A Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SL4A - Exploring Android API
SL4A is based on the Facade Design Pattern to communicate with the underlying Android API. This chapter explains the working of Façade Design Pattern and the different SL4A API facades.
What is a Facade Design Pattern?
A facade is an object that provides an interface that simppfies the access to the related interfaces in the apppcation. In other words, a façade insulates the working of the pbraries from the cpent and acts as an entry point to each subsystem level. Thus, the cpents communicate only through their facades. The following illustration explains the same.
SL4A and Android API Facades
SL4A hosts interpreters for each language it supports. The interpreters access the underlying Android APIs through an interface called a façade.
The following table psts the top-level facades and the functionapty they provide −
S.No. | Android API Facade & Description |
---|---|
1 | ActivityResultFacade It sets how your script will return information as an activity. This method imppes 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 pke reading input, notifications, launching apppcation components etc. |
3 | ApppcationManagerFacade 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 capabipties 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 pke opening a pst of contacts, making a map search, starting an activity by action etc. |
8 | ContactsFacade Allows access to contacts such as providing the contact pst for picking a contact, querying the contact pst by attributes and getting a pst 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 apppcations asynchronously. This façade provides functions to manage the event queue such as clearing the existing events, posting new events, psting, 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 pke getLastKnownLocation, startLocating, stopLocating, readLocation etc. |
12 | MediaPlayerFacade Allows playing media files, controlpng 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 pke mediaPlay, mediaPlayPause, mediaPlayClose, mediaPlaySeek,mediaPlayStart and mediaPlaySetLooping are used to control the media player. |
13 | MediaRecorderFacade This façade provides audio and video recording capabipty. 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 pke 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 pke getting the pst 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 pght,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 pke 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 functionapty 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 pke 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 quapty of the video while streaming use the webcamAdjustQuapty 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. |
Refer
for a full pst of methods provided by these facades. The subsequent chapters illustrate how to create utipties using Android Façade API functions. Advertisements