Mega Search
23.2 Million


Sign Up

Make a donation  
Proximity sensor for Android?  
News Group: embarcadero.public.delphi.firemonkey

Hello:

Anyone know if there any way to access to proximity sensor in Android?.

Thanks!!.

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 1-Oct-2013, at 5:33 PM EST
From: Registered User
 
Re: Proximity sensor for Android?  
News Group: embarcadero.public.delphi.firemonkey
> Now, with that said, although Delphi can access any Android Java-based API, 
> it does not natively define the sensor API interfaces, so you will have to 
> manually define all of the relevant interfaces in your own code.
> 
> --
> Remy Lebeau (TeamB)

Thanks for your reply, but I'm trying to search examples and docs to write sintax, but I never program in Java and don't know the Androdid API.

Please, can you write a little example?.

Thanks!!.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 2-Oct-2013, at 6:57 PM EST
From: Registered User
 
Re: Proximity sensor for Android?  
News Group: embarcadero.public.delphi.firemonkey
> 
> > Please, can you write a little example?.
> 
> Search these forums, there have been several JNI-related examples posted 
> recently, showing how to access various Android APIs in Delphi using JNI 
> interfaces.
> 
> --
> Remy Lebeau (TeamB)

Thanks Remy, I tried to search in forum by "JNI" and "JNI Delphi" but I can't find anything.

I tried to implement code using FMX.Sensors but I'm very novice in mobile apps under Delphi, and I can't understand these java statements..., an very short code to get value of proximity sensor for me is much much more didactic than links to java code. 

I understand and I appreciate your interest in helping me, in fact, you took your time to find all these links, but please, in my limited experience, better appreciate a piece of code, so I can better understand how to implement code using JNI.

Thank you!.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 5-Oct-2013, at 10:53 AM EST
From: Registered User
 
Re: Proximity sensor for Android?  
News Group: embarcadero.public.delphi.firemonkey
The first step it's a run sample from RAD Studio that named SensorInfo on your device. On the tab Biometric you can see HumanProximity. If it's true you can get access to this sensor using RTL.

Add unit System.Sensors into uses list and drop TTimer
{code}
type
  TForm1 = class(TForm)
    Label1: TLabel;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    FHumanProximity: TCustomBiometricSensor; // Declare it
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
var
  LSensorArray : TSensorArray;
  LSensor : TCustomSensor;
begin // Get the sensor list and find that we want
  TSensorManager.Current.Activate();
  LSensorArray := TSensorManager.Current.GetSensorsByCategory(TSensorCategory.Biometric);
  for LSensor in LSensorArray do
    if TCustomBiometricSensor(LSensor).SensorType = TBiometricSensorType.HumanProximity then
      FHumanProximity := TCustomBiometricSensor(LSensor);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin // just poll it
  if FHumanProximity <> nil then
    Label1.Text := FHumanProximity.HumanProximity.ToString;
end;

end.
{code}
I hope I help you

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 13-May-2014, at 9:34 AM EST
From: Nikolay Meleshkin