|
1 | | -** Using Location, Sensor and Text to speech services ** |
| 1 | +Android |
| 2 | +======= |
2 | 3 |
|
3 | | -Applies to version 0.12.8 |
| 4 | +> Using Location, Sensor and Text to speech services. Applies to version 0.12.8 (and above) |
4 | 5 |
|
5 | 6 | To use the following services, your program must start with the following two lines: |
| 7 | + |
6 | 8 | ``` |
7 | 9 | option predef load modules |
8 | 10 | import android |
9 | 11 | ``` |
10 | 12 |
|
11 | 13 | The first line tell SmallBASIC to dynamically load runtime modules. The second line imports the android module. |
12 | 14 |
|
13 | | -1. Location |
| 15 | +## Location |
14 | 16 |
|
15 | 17 | GPS_ON |
| 18 | + |
16 | 19 | ``` |
17 | 20 | android.gps_on() |
18 | 21 | ``` |
19 | 22 |
|
20 | 23 | Instructs the system to commence recording location information. Note: This relies on the device location services being enabled by the user. |
21 | 24 |
|
22 | 25 | GPS_OFF |
| 26 | + |
23 | 27 | ``` |
24 | 28 | android.gps_off() |
25 | 29 | ``` |
26 | 30 |
|
27 | 31 | Turns off recording of location information. |
28 | 32 |
|
29 | 33 | LOCATION |
| 34 | + |
30 | 35 | ``` |
31 | 36 | l = android.location() |
32 | 37 | ``` |
33 | 38 |
|
34 | 39 | Returns a MAP variable holding the following details: |
35 | 40 |
|
36 | | -latitude - the latitude, in degrees. |
37 | | -longitude - the longitude, in degrees. |
38 | | -speed - the speed if it is available, in meters/second over ground. |
39 | | -accuracy - the estimated accuracy of this location, in meters. |
40 | | -altitude - altitude if available, in meters |
41 | | -bearing - the bearing, in degrees |
42 | | -provider - whether data obtained from GPS or network |
| 41 | +- latitude - the latitude, in degrees. |
| 42 | +- longitude - the longitude, in degrees. |
| 43 | +- speed - the speed if it is available, in meters/second over ground. |
| 44 | +- accuracy - the estimated accuracy of this location, in meters. |
| 45 | +- altitude - altitude if available, in meters |
| 46 | +- bearing - the bearing, in degrees |
| 47 | +- provider - whether data obtained from GPS or network |
43 | 48 |
|
44 | 49 | Note: the location data is updated internally at 1 second intervals. |
45 | 50 |
|
46 | | -For more details, see: https://developer.android.com/reference/android/location/Location.html |
| 51 | +For more details, see: <https://developer.android.com/reference/android/location/Location.html> |
47 | 52 |
|
48 | | -2. Sensor |
| 53 | +## Sensor |
49 | 54 |
|
50 | 55 | SENSOR_ON |
| 56 | + |
51 | 57 | ``` |
52 | 58 | const SensorAccelerometer = 0 |
53 | 59 | const SensorMagneticField = 1 |
@@ -60,76 +66,84 @@ android.sensor_on(n) |
60 | 66 | Enables the given sensor (currently only one may be enabled at a time). Throws an exception if the given sensor is not available (for example, not all devices have a gyroscope). |
61 | 67 |
|
62 | 68 | SENSOR_OFF |
| 69 | + |
63 | 70 | ``` |
64 | 71 | android.sensor_off() |
65 | 72 | ``` |
66 | 73 |
|
67 | 74 | Disables any active sensor. |
68 | 75 |
|
69 | 76 | SENSOR |
| 77 | + |
70 | 78 | ``` |
71 | 79 | s = android.sensor() |
72 | 80 | ``` |
73 | 81 |
|
74 | 82 | Returns a MAP variable holding sensor details. |
75 | 83 | x, y, z - The spatial position |
76 | | -light - (SensorLight) |
| 84 | +light - (SensorLight) |
77 | 85 | distance - (SensorProximity) |
78 | 86 |
|
79 | 87 | For more details, see: |
80 | | -http://i.stack.imgur.com/skBui.jpg |
81 | | -https://developer.android.com/reference/android/hardware/SensorEvent.html |
82 | 88 |
|
83 | | -3. Text to speech |
| 89 | +- <http://i.stack.imgur.com/skBui.jpg> |
| 90 | +- <https://developer.android.com/reference/android/hardware/SensorEvent.html> |
| 91 | + |
| 92 | +## Text to speech |
84 | 93 |
|
85 | | -Output data as spoken text. |
| 94 | +Output data as spoken text. |
86 | 95 |
|
87 | 96 | Notes: |
88 | 97 | - The text to speech module takes a moment to initialise. This is performed the first time you call SPEAK. |
89 | 98 | - You may want to turn off the system setting to send TTS usage statistics to google before using this feature. |
90 | 99 |
|
91 | 100 | TTS_PITCH |
| 101 | + |
92 | 102 | ``` |
93 | 103 | android.tts_pitch(n) |
94 | 104 | ``` |
95 | 105 |
|
96 | 106 | Sets the voice pitch (default is 1.0). |
97 | 107 |
|
98 | 108 | TTS_RATE |
| 109 | + |
99 | 110 | ``` |
100 | 111 | android.tts_rate(n) |
101 | 112 | ``` |
102 | 113 |
|
103 | 114 | Sets the rate of speaking (default is 1.0) |
104 | 115 |
|
105 | 116 | TTS_LANG |
| 117 | + |
106 | 118 | ``` |
107 | 119 | android.tts_lang(s) |
108 | 120 | ``` |
109 | 121 |
|
110 | 122 | Sets the locale, for example "en", "de", "fr" for English, German, France. May cause the system to download the language codec if not already installed. |
111 | 123 |
|
112 | 124 | TTS_OFF |
| 125 | + |
113 | 126 | ``` |
114 | 127 | android.tts_off() |
115 | 128 | ``` |
116 | 129 |
|
117 | | -Turns off text to speech output. |
| 130 | +Turns off text to speech output. |
118 | 131 |
|
119 | 132 | SPEAK |
| 133 | + |
120 | 134 | ``` |
121 | 135 | android.speak(text) |
122 | 136 | ``` |
123 | 137 |
|
124 | 138 | Performs text to speech (default is ENGLISH). |
125 | 139 |
|
126 | | -** How to edit and run a program ** |
| 140 | +## How to edit and run a program |
127 | 141 |
|
128 | | -1. Internal editor: |
| 142 | +### Internal editor: |
129 | 143 | - Display the menu, then click Editor [ON] |
130 | | -- Tap a file name in the browser. |
| 144 | +- Tap a file name in the browser. |
131 | 145 |
|
132 | | -2. Desktop SmallBASIC |
| 146 | +### Desktop SmallBASIC |
133 | 147 | - Enter the port number in the setup screen. |
134 | 148 | - Connect your desktop machine and your mobile device to the same wifi network. |
135 | 149 | - Launch desktop SmallBASIC. |
@@ -139,40 +153,39 @@ Performs text to speech (default is ENGLISH). |
139 | 153 | - Enter the security code, then press enter. |
140 | 154 | - Once the settings are successful, you can press F4 to upload your program again. |
141 | 155 |
|
142 | | -3. File browser: |
| 156 | +### File browser: |
143 | 157 | - Write and debug the program with desktop SmallBASIC. |
144 | 158 | - Copy the .bas file to your SDCard. |
145 | 159 | - Launch SmallBASIC, then navigate to the file in the built-in file browser, then tap the link to run. |
146 | 160 | - or, navigate to the file in the system file browser, then tap the link to start SmallBASIC and run the program. |
147 | 161 |
|
148 | | -4. Separate editor on device: |
| 162 | +### Separate editor on device: |
149 | 163 | - Write your SmallBASIC program in a separate editor on your device. |
150 | 164 | - Task switch to SmallBASIC, then run the program using the built-in file browser. |
151 | 165 |
|
152 | | -5. Web Service: |
| 166 | +### Web Service: |
153 | 167 | - Enter the port number in the setup screen. |
154 | 168 | - Connect your desktop machine and your mobile device to the same wifi network. |
155 | 169 | - Launch a desktop browser then enter http://: |
156 | 170 | - A simple web page is displayed. Enter your SmallBASIC program then click run. |
157 | 171 |
|
158 | | -6. QRcode: |
| 172 | +### QRcode: |
159 | 173 | - Write and debug the program with desktop SmallBASIC. |
160 | 174 | - Convert the program to an QRCode image. |
161 | 175 | - Scan the QRCode in the separate decoder program. |
162 | 176 | - Click okay to launch SmallBASIC and the encoded program. |
163 | 177 |
|
164 | 178 | Note: the tool to convert source code to QR codes is here: https://github.com/smallbasic/SmallBASIC/tree/master/web/qrcode |
165 | 179 |
|
166 | | -** Playing music ** |
167 | | - |
168 | | -Applies to version 0.12.8 |
| 180 | +## Playing music |
169 | 181 |
|
170 | 182 | PLAY("file:///sdcard/VoiceRecorder/recordings/hello.mp3") |
171 | 183 |
|
172 | 184 | Use the PLAY command with the prefix "file://" to play an audio track. For supported formats, see: |
173 | 185 |
|
174 | | -https://developer.android.com/guide/appendix/media-formats.html |
| 186 | +<https://developer.android.com/guide/appendix/media-formats.html> |
| 187 | + |
| 188 | +## Release history |
175 | 189 |
|
176 | | -** Release history ** |
177 | | -http://smallbasic.sourceforge.net/?q=node/1217 |
| 190 | +[Android changelog](android_changelog.html) |
178 | 191 |
|