I am sure I am making something wrong... so this is more a question than an "issue". Anyway, here it goes.
public class ViewDeviceActivity extends Activity {
BluetoothSPP bt;
protected void onCreate(Bundle savedInstanceState) {
bt = new BluetoothSPP(this);
}
public void onStart() {
bt.setBluetoothConnectionListener(new BluetoothSPP.BluetoothConnectionListener() {
public void onDeviceConnected(String name, String address) {
Log.i("Sensorino", "Connected, sending data...");
bt.send("blah",false);
}
});
bt.setOnDataReceivedListener(new BluetoothSPP.OnDataReceivedListener() {
public void onDataReceived(byte[] data, String message) {
// Do something when data incoming
Log.i("Sensorino", "Received bytes: "+data.length);
}
});
bt.setupService();
bt.startService(BluetoothState.DEVICE_OTHER);
Log.i("Sensorino", "Connecting to " + device.getRemote_address());
bt.connect(device.getRemote_address());
}
}
The problem is that I am able to send (on the other end I see "blah") but not able to receive. I have tried with both the sample BluetoothChat from googlecode and from my HC-05 device: same with both.
The thing that drives me mad is that I ACTUALLY see the data getting into the device (I enabled Bluetooth Debugging and see the packet with the data in the /sdcard) but the data does not reach my activity.
It would actually help if you tell me what's the minimum methods and the right order to call them in order to have I/O working. If I understand correctly (I am not an Android expert) I am doing the following:
bt = new BluetoothSPP(this);
bt.setBluetoothConnectionListener(new xxx);
bt.setOnDataReceivedListener(new xxx);
bt.setupService();
bt.startService(BluetoothState.DEVICE_OTHER);
bt.connect(device.getRemote_address());
bt.send("blah",false);
I tried shuffling the setupService and startService up and down with the same result.