Implementación de OBEX PUSH Server en Android 2.3

Necesito configurar un servidor OBEX en la aplicación en un dispositivo Android 2.3. Utilizando el código de ejemplo de chat Bluetooth, pude configurar un servidor OBEX. Sin embargo, el servidor necesita utilizar un UUID personalizado para que el servicio no esté registrado como un "Servidor OBEX"

# sdptool browse local ...(snip)... Service Name: OBEX Object Push Service RecHandle: 0x10000 Service Class ID List: UUID 128: ab123abc-1a2b-3c4d-5d7f-1234567890ab Protocol Descriptor List: "L2CAP" (0x0100) "RFCOMM" (0x0003) Channel: 18 

Por lo tanto, cuando recibo datos, parece que estoy recibiendo una solicitud de conexión OBEX sin procesar:

 80 00 07 10 00 04 00 00 00 00 ...(snip)... 00 00 00 (1kb file) 

¿Hay una implementación de OBEX que puedo usar o tengo que implementar el protocolo yo mismo?

No quiero usar el servidor OBEX incorporado – esto tiene que ser en la aplicación. He intentado BlueCove pero lo abandoné cuando tuve problemas para registrar un servicio.

Sí, vi este post y leer el enlace en él, pero por golly, debe haber una manera más fácil!

Terminé implementando el protocolo yo mismo. No era tan peludo como me imaginaba. Ya que esperaba sólo un cliente específico para conectarse y sabía que el cliente sólo estaría empujando un archivo que era capaz de implementar parcialmente sólo las secciones del protocolo que necesitaba.

Algunos documentos que ayudaron con la comprensión del protocolo OBEX fueron Obex13.pdf en: http://gitorious.org/gammu/gsm-docs/trees/e5161a75fb1e1c1608959b27ae3c3940bcf0911b/standards/obex

Un fragmento rápido de cómo analizo el flujo de entrada de sockets: (Nota OBEXUtils y OBEXConstants son mis clases.)

 try { //Read all bytes passed in bytes = mmInStream.read(buffer); //Ensure we have the entire packet before we proceed // Packet length is in the 1st and 2nd byte expectedLength = OBEXUtils.bytesToShort(buffer[OBEXConstant.LENGTH_IDENTIFIER], buffer[OBEXConstant.LENGTH_IDENTIFIER + 1]); packetLength = bytes; //Keep reading until we get what we expect. while (packetLength < expectedLength) { bytes = mmInStream.read(buffer, packetLength, maxPacketSize); packetLength += bytes; } //Switch on Packet Header switch (buffer[OBEXConstant.HEADER_IDENTIFIER]) { case OBEXConstant.CONNECT: //Parse the packet and return an acknowledgement packet write(OBEXConnect.parsePacket(buffer)); break; case OBEXConstant.PUT: case OBEXConstant.PUT_FINAL: //Parse the PUT packet and return an acknowledgement packet //For Parsing PUT packets I referred to the android and bluecove implementations write(putPacket.appendPacket(buffer, packetLength)); break; case OBEXConstant.DISCONNECT: //Parse the packet and return an acknowledgement packet write(OBEXDisconnect.parsePacket(buffer)); break; case OBEXConstant.GET: case OBEXConstant.GET_FINAL: case OBEXConstant.SETPATH: case OBEXConstant.SETPATH_FINAL: case OBEXConstant.SESSION: //Did not implement these break; case OBEXConstant.ABORT: Log.w(Constant.TAG, TAG + "ABORT Request Received"); isDisconnected = true; break; default: break; } } catch (final IOException e) { ...(snip)... } 

Snip de OBEXConstant:

 public static final byte FINAL_BIT = (byte) 0x80; public static final byte CONNECT = 0x00 | FINAL_BIT; //*high bit always set Connect choose your partner, negotiate capabilities public static final byte DISCONNECT = 0x01 | FINAL_BIT; //*high bit always set Disconnect signal the end of the session public static final byte PUT = 0x02; //(0x82) Put send an object public static final byte PUT_FINAL = PUT | FINAL_BIT; public static final byte GET = 0x03; //(0x83) Get get an object public static final byte GET_FINAL = GET | FINAL_BIT; //(0x83) Get get an object public static final byte SETPATH = 0x05; public static final byte SETPATH_FINAL = SETPATH | FINAL_BIT; public static final byte SESSION = 0x07; public static final byte ABORT = (byte) 0xFF; public static final byte OBEX_RESPONSE_CONTINUE = (byte) 0x90; public static final byte OBEX_RESPONSE_SUCCESS = (byte) 0xA0; 

Quizás esto ayude: com.android.bluetooth.pbap.BluetoothPbapObexServer

  • Android Bluetooth desde dentro del servicio
  • ¿Activar Bluetooth SPP en Android?
  • ¿Es posible conectar el teléfono android a la impresora vía bluetooth?
  • Android: Mostrar Notificación en la Vigilancia Cuando Cualquier Llamada o Notificación de la Red Social de móvil (mediante Bluetooth)
  • El conector Bluetooth de Android se bloquea
  • Android: conexión a varios dispositivos bluetooth sin emparejamiento
  • Enviar y recibir datos a través de bluetooth
  • BLE en Nexus 7 (ME370T) con android 4.4.2
  • Arquitectura Bluez: Explique esta arquitectura
  • Perfect unique_id para el dispositivo excepto IMEI, Android_ID, WLAN Mac y dirección Bluetooth
  • Obtener UUIDs de G-Shock reloj bluetooth android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.