Difference between revisions of "LazDeviceAPIs"

From Lazarus wiki
Jump to navigationJump to search
m (Text replace - "delphi>" to "syntaxhighlight>")
m (Fixed syntax highlighting)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
{{LazDeviceAPIs}}
 +
 
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.
 
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.
 +
 
__TOC__
 
__TOC__
 +
 +
 
==Introduction==
 
==Introduction==
 +
 
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.
 
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.
 +
 
==Accelerometer==
 
==Accelerometer==
  
 
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:
 
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:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
uses lazdeviceapis;
 
uses lazdeviceapis;
  
Line 37: Line 44:
 
===Android Permissions===
 
===Android Permissions===
  
Using the PositionInfo global object in Android requires adding the following permissions to the AndroidManifest.xml file of the application, as can be seen bellow.
+
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.
  
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  
 
==Messaging==
 
==Messaging==
Line 46: Line 53:
 
===Android Permissions===
 
===Android Permissions===
  
Using the Messaging global object in Android requires adding the following permissions to the AndroidManifest.xml file of the application, as can be seen bellow.
+
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.
  
<uses-permission android:name="android.permission.SEND_SMS" />
+
<uses-permission android:name="android.permission.SEND_SMS" />
 +
 
 +
==Possible Windows implementation==
 +
 
 +
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%28v=vs.85%29.aspx]]. Interested developers may be able to use those APIs to provide LazDeviceAPIs functionality.
  
 
==Roadmap==
 
==Roadmap==
 +
 
LazDeviceAPIs is currently implemented only for LCL-CustomDrawn-Android
 
LazDeviceAPIs is currently implemented only for LCL-CustomDrawn-Android
 +
 
==See Also==
 
==See Also==
*[[Custom Drawn Interface\Android]]
+
 
 +
*[[Custom Drawn Interface/Android]]
 +
*[[Talk:LazDeviceAPIs]]

Latest revision as of 00:48, 19 February 2020

Android robot.svg

This article applies to Android only.

See also: Multiplatform Programming Guide

English (en) 한국어 (ko)

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.


Introduction

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.

Accelerometer

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:

uses lazdeviceapis;

procedure TForm2.btnStartAccelClick(Sender: TObject);
begin
  Accelerometer.OnSensorChanged := @HandleAccelerometerChanged;
  Accelerometer.StartReadingAccelerometerData();
end;

procedure TForm2.btnStopAccelClick(Sender: TObject);
begin
  Accelerometer.StopReadingAccelerometerData();
end;

procedure TForm2.HandleAccelerometerChanged(Sender: TObject);
begin
  labelSensorData.Caption := Format('X=%f Y=%f Z=%f', [Accelerometer.xaxis,
    Accelerometer.yaxis, Accelerometer.zaxis]);
  DebugLn(labelSensorData.Caption);
end;

Android Permissions

This object requires no special permissions under Android.

PositionInfo

Android Permissions

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.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Messaging

Android Permissions

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.

<uses-permission android:name="android.permission.SEND_SMS" />

Possible Windows implementation

Windows 7 and up has a sensors API that gives access to sensor info (e.g. GPS); see [[1]]. Interested developers may be able to use those APIs to provide LazDeviceAPIs functionality.

Roadmap

LazDeviceAPIs is currently implemented only for LCL-CustomDrawn-Android

See Also