LazDeviceAPIs: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 1 | + | [](</File:Android_robot.svg>) | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | This article applies to [Android](</Category:Android> "Category:Android") only. | |
| 4 | 4 | ||
| 5 | - | ||
| 5 | + | See also: [[Multiplatform Programming Guide]] | |
| 6 | 6 | ||
| 7 | - | ||
| 7 | + | │ **English (en)** │ **[[LazDeviceAPIs/ko|한국어 (ko)]]** │ | |
| 8 | 8 | ||
| 9 | - | ||
| 9 | + | 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. | |
| 10 | 10 | ||
| 11 | - | ||
| 12 | - | ||
| 11 | + | ||
| 13 | 12 | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 13 | + | ## Introduction | |
| 19 | 14 | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 15 | + | 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. | |
| 24 | 16 | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 17 | + | ## Accelerometer | |
| 18 | + | ||
| 19 | + | 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: | |
| 31 | 20 | ``` | |
| 21 | + | uses lazdeviceapis; | |
| 22 | + | ||
| 23 | + | procedure TForm2.btnStartAccelClick(Sender: TObject); | |
| 24 | + | begin | |
| 25 | + | Accelerometer.OnSensorChanged := @HandleAccelerometerChanged; | |
| 26 | + | Accelerometer.StartReadingAccelerometerData(); | |
| 27 | + | end; | |
| 28 | + | ||
| 29 | + | procedure TForm2.btnStopAccelClick(Sender: TObject); | |
| 30 | + | begin | |
| 31 | + | Accelerometer.StopReadingAccelerometerData(); | |
| 32 | + | end; | |
| 33 | + | ||
| 34 | + | procedure TForm2.HandleAccelerometerChanged(Sender: TObject); | |
| 35 | + | begin | |
| 36 | + | labelSensorData.Caption := Format('X=%f Y=%f Z=%f', [Accelerometer.xaxis, | |
| 37 | + | Accelerometer.yaxis, Accelerometer.zaxis]); | |
| 38 | + | DebugLn(labelSensorData.Caption); | |
| 39 | + | end; | |
| 40 | + | ``` | |
| 32 | 41 | ||
| 33 | 42 | ### Android Permissions | |
| 34 | 43 | ||
| 35 | - | ||
| 44 | + | This object requires no special permissions under Android. | |
| 36 | 45 | ||
| 37 | 46 | ## PositionInfo | |
| 38 | 47 | ||
| 39 | 48 | ### Android Permissions | |
| 40 | 49 | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 50 | + | 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. | |
| 51 | + | ``` | |
| 44 | 52 | <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
| 45 | - | ||
| 53 | + | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
| 46 | 54 | ``` | |
| 47 | 55 | ||
| 48 | 56 | ## Messaging | |
| 49 | 57 | ||
| 50 | 58 | ### Android Permissions | |
| 51 | 59 | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 60 | + | 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. | |
| 61 | + | ``` | |
| 55 | 62 | <uses-permission android:name="android.permission.SEND_SMS" /> | |
| 56 | 63 | ``` | |
| 57 | 64 | ||
| 58 | 65 | ## Possible Windows implementation | |
| 59 | 66 | ||
| 60 | - | ||
| 67 | + | Windows 7 and up has a sensors API that gives access to sensor info (e.g. GPS); see [[[1]](<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. | |
| 61 | 68 | ||
| 62 | 69 | ## Roadmap | |
| 63 | 70 | ||
| 64 | - | ||
| 71 | + | LazDeviceAPIs is currently implemented only for LCL-CustomDrawn-Android | |
| 65 | 72 | ||
| 66 | 73 | ## See Also | |
| 67 | 74 | ||
| 68 | - | ||
| 69 | - | ||
| 75 | + | * [[Custom Drawn Interface/Android]] | |
| 76 | + | * [Talk:LazDeviceAPIs](</Talk:LazDeviceAPIs> "Talk:LazDeviceAPIs") | |
| 70 | 77 | ||
| 71 | 78 | --- | |
| 72 | - | ||
| 79 | + | *From the Free Pascal wiki, page "LazDeviceAPIs", as the Internet Archive kept it on 2024-09-20, last changed on 2020-02-19. 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).* |
