android - Send a byte via bluetooth -



android - Send a byte via bluetooth -

i wanted know how send byte in binary form via bluetooth. @ moment utilize code:

msendbutton = (button) findviewbyid(r.id.button_send); msendbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { // send message using content of edit text widget textview view = (textview) findviewbyid(r.id.edit_text_out); string message = view.gettext().tostring(); sendmessage(message); } });

only in way sends string , not byte.

thanks help.

this source:

private void sendmessage(string message) { // check we're connected before trying if (mchatservice.getstate() != bluetoothchatservice.state_connected) { toast.maketext(this, r.string.not_connected, toast.length_short).show(); return; } // check there's send if (message.length() > 0) { // message bytes , tell bluetoothchatservice write byte[] send = message.getbytes(); mchatservice.write(send); // reset out string buffer 0 , clear edit text field moutstringbuffer.setlength(0); moutedittext.settext(moutstringbuffer); } }

according source code, sending byte array write method. if called mchatservice.write(byte[]data) calling this, should work:

mchatservice.write(new byte[]{5});

where 5 byte value want send, in other words, phone call sendmessage method translating string byte array sent bluetooth service.

android bluetooth

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -