Home > Mobile >  Bluetoothchat program receive a machine to send data content is not
Bluetoothchat program receive a machine to send data content is not

Time:09-27

New android consult
Under a machine sent 11 bytes starting with fixed data such as 0 xfe 0 xfe 0 XCC 0 xc2 as the beginning of the application in judgment only 0 xfe 0 xfe
Middle including fixed 0 x00 to 0 x00 0 x00 0 x01 0 x00 xd5 0 0 xc2
Bluetooth example of using Google byte& & 0 XFF to unsigned
But only at the beginning to judge the first complete data string won't get back again


 case MESSAGE_READ: 

Int copyflag=1;
Byte [] rxBuf=(byte []) MSG. Obj.
//the construct a string from the valid bytes in the buffer
String rxMsg=new String (rxBuf, 0, MSG. Arg1);
//the Log. I (" - Read: "rxMsg +" | "+ rxMsg. Length () +" | "+ rxBuf. Length +" | "+ ((byte []) MSG. Obj). The length +" | "+ MSG. Arg1);

String tmp_str="";

for(int i=0; i{
If (UByte (rxBuf [I])==0 xfe)
{copyflag=1; Tmp_str +=String. The valueOf ((char) rxBuf [I]); }
Else if (UByte (rxBuf [I])==0 xfe & amp; & Copyflag==1)
{copyflag=2; Tmp_str +=String. The valueOf ((char) rxBuf [I]); }
Else if (UByte (rxBuf [I])==0 xc2 & amp; & Copyflag==2)
{copyflag=3; break; }

If (copyflag==2)
Tmp_str +=String. The valueOf ((char) rxBuf [I]);
}
If (copyflag==3)
Log. I (" -- Data: ", "" + tmp_str);

Tmp_str="";
Copyflag=1;

break;
  • Related