I am using Android example code to modify. Just want to get the package but my code changes here only
private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MESSAGE_STATE_CHANGE: if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1); switch (msg.arg1) { case BluetoothChatService.STATE_CONNECTED: mTitle.setText(R.string.title_connected_to); mTitle.append(mConnectedDeviceName); mConversationArrayAdapter.clear(); break; case BluetoothChatService.STATE_CONNECTING: mTitle.setText(R.string.title_connecting); break; case BluetoothChatService.STATE_LISTEN: case BluetoothChatService.STATE_NONE: mTitle.setText(R.string.title_not_connected); break; } break; case MESSAGE_WRITE: byte[] writeBuf = (byte[]) msg.obj;
and BluetoothChatService
public void run() { Log.i(TAG, "BEGIN mConnectedThread"); byte[] buffer = new byte[1024]; int bytes;
and add this function
package com.example.android.BluetoothChat; public class BytesTrans { public static String byte2HexString(byte b) { String ret = ""; String hex = Integer.toHexString(b & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } ret += hex.toUpperCase() + " "; return ret; } public static String bytes2HexString(byte[] b, int count) { String ret = ""; for (int i = 0; i < count; i++) { String hex = Integer.toHexString(b[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } ret += hex.toUpperCase() + " "; } return ret; } public static int hexToTen(String b) { int D2 = Integer.parseInt(b,16); return D2; } }
but this program sometimes even displays my sending package
I send the package as follows:
aa072108200012021409343900000000000000000000000000000000000000000000000297c0fe6b
but someday get the package:
aa000297c0fe6b02131452470000000000000000000000000000000000000000000297c0fe6b
how can i change my code to get a full frame packet
source share