LazDeviceAPIs: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | LazDeviceAPIs is a LCL unit which offers an interface to various hardware devices, such as the accelerometer, GPS positioning, SMS sending, etc. It is mostly designed for smartphone/mobile platforms, but it might eventually be ported to desktops too. | |
| 2 | 2 | ||
| 3 | 3 | ## Introduction | |
| 4 | 4 | ||
| 5 | 5 | LazDeviceAPIs was modeled to be similar to other APIs for hardware devices from the LCL. Historically we had two hardware global objects: Mouse and Screen, respectively for the pointing device (Mouse is also utilized for touch messages) and Screen for the display. In LazDeviceAPIs there are global objects: Accelerometer, PositionInfo, Messaging, etc. | |
| 6 | 6 | ||
| 7 | 7 | ## Accelerometer | |
| 8 | 8 | ||
| 9 | 9 | The Accelerometer is very easy to use. Just call Accelerometer.StartReadingAccelerometerData to start listening to the accelerometer sensor and call Accelerometer.StopReadingAccelerometerData to stop listening to it: | |
| 10 | 10 | ||
| 11 | 11 | ``` pascal | |
| 12 | 12 | uses lazdeviceapis; | |
| 13 | 13 | ||
| 14 | 14 | procedure TForm2.btnStartAccelClick(Sender: TObject); | |
| 15 | 15 | begin | |
| 16 | 16 | Accelerometer.OnSensorChanged := @HandleAccelerometerChanged; | |
| 17 | 17 | Accelerometer.StartReadingAccelerometerData(); | |
| 18 | 18 | end; | |
| 19 | 19 | ||
| 20 | 20 | procedure TForm2.btnStopAccelClick(Sender: TObject); | |
| 21 | 21 | begin | |
| 22 | 22 | Accelerometer.StopReadingAccelerometerData(); | |
| 23 | 23 | end; | |
| 24 | 24 | ||
| 25 | 25 | procedure TForm2.HandleAccelerometerChanged(Sender: TObject); | |
| 26 | 26 | begin | |
| 27 | 27 | labelSensorData.Caption := Format('X=%f Y=%f Z=%f', [Accelerometer.xaxis, | |
| 28 | 28 | Accelerometer.yaxis, Accelerometer.zaxis]); | |
| 29 | 29 | DebugLn(labelSensorData.Caption); | |
| 30 | 30 | end; | |
| 31 | 31 | ``` | |
| 32 | 32 | ||
| 33 | 33 | ### Android Permissions | |
| 34 | 34 | ||
| 35 | 35 | This object requires no special permissions under Android. | |
| 36 | 36 | ||
| 37 | 37 | ## PositionInfo | |
| 38 | 38 | ||
| 39 | 39 | ### Android Permissions | |
| 40 | 40 | ||
| 41 | 41 | Using the PositionInfo global object in Android requires adding the following permissions to the AndroidManifest.xml file of the application, as can be seen below. | |
| 42 | 42 | ||
| 43 | - | ||
| 44 | - | ||
| 43 | + | ``` pascal | |
| 44 | + | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
| 45 | + | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
| 46 | + | ``` | |
| 45 | 47 | ||
| 46 | 48 | ## Messaging | |
| 47 | 49 | ||
| 48 | 50 | ### Android Permissions | |
| 49 | 51 | ||
| 50 | 52 | Using the Messaging global object in Android requires adding the following permissions to the AndroidManifest.xml file of the application, as can be seen below. | |
| 51 | 53 | ||
| 52 | - | ||
| 54 | + | ``` pascal | |
| 55 | + | <uses-permission android:name="android.permission.SEND_SMS" /> | |
| 56 | + | ``` | |
| 53 | 57 | ||
| 54 | 58 | ## Possible Windows implementation | |
| 55 | 59 | ||
| 56 | 60 | Windows 7 and up has a sensors API that gives access to sensor info (e.g. GPS); see [[http://msdn.microsoft.com/en-us/library/windows/desktop/dd318936(v=vs.85).aspx|http://msdn.microsoft.com/en-us/library/windows/desktop/dd318936%28v=vs.85%29.aspx]]. Interested developers may be able to use those APIs to provide LazDeviceAPIs functionality. | |
| 57 | 61 | ||
| 58 | 62 | ## Roadmap | |
| 59 | 63 | ||
| 60 | 64 | LazDeviceAPIs is currently implemented only for LCL-CustomDrawn-Android | |
| 61 | 65 | ||
| 62 | 66 | ## See Also | |
| 63 | 67 | ||
| 64 | 68 | - [[Custom Drawn Interface/Android]] | |
| 65 | 69 | - Talk:LazDeviceAPIs | |
| 66 | 70 | ||
| 67 | 71 | --- | |
| 68 | 72 | *From the Free Pascal wiki, page "LazDeviceAPIs", as it stood on 2020-02-18 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
