unit Unit_2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
Androidapi.JNI.BluetoothAdapter,
Androidapi.JNI.JavaTypes,
Androidapi.JNIBridge,
Android.JNI.Toast,
Androidapi.Helpers,
FMX.ListBox, FMX.Layouts, FMX.Memo, FMX.Edit, FMX.Objects, FMX.ListView.Types,
FMX.ListView, System.Rtti, FMX.Grid, Data.Bind.GenData,
System.Bindings.Outputs, Fmx.Bind.Editors, Data.Bind.EngExt,
Fmx.Bind.DBEngExt, Data.Bind.Components, Data.Bind.ObjectScope,
FMX.ListView.Appearances, FMX.ListView.Adapters.Base,
FMX.Controls.Presentation;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
ListView1: TListView;
procedure FormShow(Sender: TObject);
procedure ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormShow(Sender: TObject);
var
s:string;
i:integer;
list:TStringList;
begin
list:=TStringList.Create; //crea un listado
s:=checkBluetooth; // verifica que el dispositivo se encuentre encendido
Toast(s); //imprime el estado del dispositivo
if pos('disabled',s)<>0 then exit; //se sale si el bluetooth esta apagado
list.Clear; //limpia la variable list
list.AddStrings(getbonded); // produce un listado de dispositivos
listview1.Items.Clear; //limpia listview1
for i := 0 to list.Count-1 do
begin
ListView1.items.add.Text:=list[i].Split(['='])[0]; //asocia el Nombre del Bluetooth
ListView1.Items[i].Detail:=list[i].Split(['='])[1]; //asocia la Mac del Bluetooth
end;
label4.Text:=i.ToString+' Dispositivos Emparejados';
end;
procedure TForm1.ListView1ItemClick(const Sender: TObject;
const AItem: TListViewItem);
begin
label2.Text:='Dispositivo #'+(AItem.Index+1).toString;
label3.Text:='Nombre: '+Aitem.text;
label4.Text:='MAC: '+Aitem.Detail;
end;
end.
Codigo de programación