Foros del Web » Programando para Internet » Android »

Clase envio texto en android

Estas en el tema de Clase envio texto en android en el foro de Android en Foros del Web. Hola amigos recientemente e encontrado esta clase de android que si no me equivoco perite enviar un texto a un dispositivo previamente pareado @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); ...
  #1 (permalink)  
Antiguo 07/08/2012, 13:37
Avatar de diegovazgonz  
Fecha de Ingreso: octubre-2010
Ubicación: Ourense
Mensajes: 184
Antigüedad: 13 años, 5 meses
Puntos: 11
Clase envio texto en android

Hola amigos recientemente e encontrado esta clase de android que si no me equivoco perite enviar un texto a un dispositivo previamente pareado

Código Javascript:
Ver original
  1. public class BluetoothWorker {
  2.  
  3. private static UUID generalUuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  4.  
  5. private static BluetoothSocket socket;
  6.  
  7.  
  8. private static BluetoothSocket getBluetoothSocket(){
  9.  
  10.     BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  11.     mBluetoothAdapter.cancelDiscovery();
  12.     Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
  13.     // If there are paired devices
  14.     if (pairedDevices.size() > 0) {
  15.         // Loop through paired devices
  16.         for (BluetoothDevice device : pairedDevices) {
  17.             // Add the name and address to an array adapter to show in a ListView
  18.             if(device.getName().equalsIgnoreCase(("MIGUEL-PC"))){
  19.                 try {
  20.                     return device.createRfcommSocketToServiceRecord(generalUuid);
  21.                 } catch (IOException e) {
  22.                     return null;
  23.                 }
  24.             }
  25.         }
  26.     }
  27.     return null;
  28. }
  29.  
  30. public static boolean sendData(String status){
  31.  
  32.         socket = getBluetoothSocket();
  33.         try {
  34.             socket.connect();
  35.         } catch (IOException e) {
  36.             // TODO Auto-generated catch block
  37.             socket = null;
  38.         }
  39.  
  40.     if(socket != null){
  41.         try {      
  42.  
  43.             socket.getOutputStream().write(status.getBytes());
  44.             socket.getOutputStream().flush();
  45.             socket.close();
  46.             return true;
  47.         } catch (IOException e) {
  48.             socket = null;
  49.             return false;
  50.         }
  51.     }else{
  52.         return false;
  53.     }
  54. }
  55. }

mi pregunta es como lo colocaria en mi activiti principal y como invocarlo por ejemplo al pulsar un boton, gracias

NOTA: el autor del texto dice que falla habeces ,si alguien lo sabe mejorar se agradece

Etiquetas: bluetooth
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:03.