Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Desarrollo en Delphi para Android
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos


Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-05-2014
Avatar de kurono
[kurono] kurono is offline
Miembro Premium
 
Registrado: jul 2007
Ubicación: Republica Dominicana
Posts: 1.126
Poder: 18
kurono Va por buen camino
Error en Aplicacion para Conexion Bluetooth

hola amigos como estan navegando por la internet me encontre con un codigo para android que en lista los dipositivo bluetooth y se conecta al selecionar un dipositivo pero a mi me da el siguiente error runtime execption can ' t create handler inside thread that has not called looper prepare el error se produce en el evento FormShow, aqui muestro el codigo completo

Código Delphi [-]
unit Unit1;

// This example is derived from Björn Hansen's Bluetooth SPP / RS232 to control LED Light written with Delphi XE5 demo project
// Parts of this project are based on the Project: http://www.pclviewer.com/android/
// And some of the implementation source code for this Bluetooth paired device browser is derived from the Delphi project downloadable from http://goo.gl/E24OQW

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,
  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;

type
  TForm1 = class(TForm)
    reload: TButton;
    Label1: TLabel;
    ListView1: TListView;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure ListView1ItemClick(const Sender: TObject;
      const AItem: TListViewItem);
  private
    { private declarations }
  public
    { public declarations }
    targetMACAddress:string; // MAC address of selected device
    ostream:JOutputStream;
    istream:JInputstream;
    uid:JUUID;              // UUID for SPP traffic
    Sock:JBluetoothSocket;
    Adapter:JBluetoothAdapter;  // Local BLUETOOTH adapter
    remoteDevice:JBluetoothDevice;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormShow(Sender: TObject);
var
  s:string;                                  //  en este evento es que se produce el error
  i:integer;
  list:TStringList;
begin
  list:=TStringList.Create;
  s:=checkBluetooth; // Make sure bluetooth is enabled
  if pos('disabled',s)<>0 then
  begin
    ShowMessage('Please turn on Bluetooth  and Retry');
    exit
  end;

  // This is the well known SPP UUID for connection to a Bluetooth serial device
  uid:=TJUUID.JavaClass.fromString(stringtojstring('00001101-0000-1000-8000-00805F9B34FB'));

  list.Clear;
  list.AddStrings(getbonded);    // produce a list of bonded/paired devices

  listview1.Items.Clear;  // clear list and rebuild it
  listview1.BeginUpdate;
  for i := 0 to list.Count-1 do
  begin
    listview1.Items.Add;
    listview1.Items.Item[i].Text:=list[i].Split(['='])[0];
    listview1.Items.Item[i].Detail:=list[i].Split(['='])[1];
  end;
  listview1.EndUpdate
end;

procedure TForm1.ListView1ItemClick(const Sender: TObject;
  const AItem: TListViewItem);
begin

  ShowMessage('You selected: '+Aitem.Text);

  // depending on the bluetooth device selected - do something with it
  targetMACAddress:=Aitem.Detail;
  if trim(targetMACAddress)='' then exit;

  Adapter:=TJBluetoothAdapter.JavaClass.getDefaultAdapter;
  remoteDevice:=Adapter.getRemoteDevice(stringtojstring(targetMACAddress));
  sock:=remoteDevice.createRfcommSocketToServiceRecord(UID);
  try
    sock.connect;
   except
    ShowMessage('Could not connect to BlueTooth device');
  end;
  if not sock.isConnected then
  begin
    ShowMessage('Failed to connect to Try again...');
    exit;
  end;
  listview1.Visible:=false;     // hide the chooser
  label1.Visible:=false;        // hide the chooser
  reload.Visible:=false;        // hide the chooser
end;

end.

cual puede ser el problema

Última edición por kurono fecha: 12-05-2014 a las 00:08:40.
Responder Con Cita
  #2  
Antiguo 12-05-2014
Avatar de kurono
[kurono] kurono is offline
Miembro Premium
 
Registrado: jul 2007
Ubicación: Republica Dominicana
Posts: 1.126
Poder: 18
kurono Va por buen camino
amigos nuevamente e resuelto el problema y resulta que mi celular no es compatible con este tipo de aplicacion ya que probe la aplicacion en un sony Xperia -M y funciona
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Emparejar dispositivos bluetooth sur-se Varios 0 14-01-2010 11:44:00
programar bluetooth nitoman C++ Builder 0 02-11-2008 11:30:41
Conexion de movil con bluetooth con un pc kapullok_2006 Varios 1 30-10-2007 19:18:31
SDK C++ delphi Bluetooth Preguntas Descendents Varios 2 01-04-2007 19:07:05
Error de aplicación para un perfil en W2000 orodriguezc Windows 0 10-03-2004 01:10:26


La franja horaria es GMT +2. Ahora son las 13:05:53.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi