mBtnSendData.setOnClickListener(new Button.OnClickListener() {
Timer buttonTimer = new Timer();
@Override
public void onClick(View view) {
if (mThreadConnectedBluetooth != null) {
String SendData1 = mTvSendData1.getText().toString();
String SendData2 = mTvSendData2.getText().toString();
String SendData = SendData1 + SendData2;
mTvSendData.setText(SendData);
mThreadConnectedBluetooth.write(mTvSendData.getText().toString());
}
mBtnSendData.setEnabled(false);
buttonTimer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mBtnSendData.setEnabled(true);
}
});
}
}, 15000);
}
});
When you press the button called mBtnSendData, you are creating a source that binds the information created by the application into a string.
Next, I'm creating a source to pause mBtnSendData for about 15 seconds and then reactivate it... It works fine without Bluetooth connection, but if you try to connect Bluetooth and send information, you will get an error.
I would like to ask you how to modify it.
android studio bluetooth button
if (mThreadConnectedBluetooth != null) {
.
.
.
mThreadConnectedBluetooth.write(...);
}
I don't think there was an error because this code wasn't executed.
Please read the error message and resolve the error where you send the data to Bluetooth.
© 2024 OneMinuteCode. All rights reserved.