可能是我的问题是错误的。但在下面的代码中只有一个是写入输出,其他没有显示。但两者都在同一个循环中。请帮助我。
private Runnable updateTimerThread = new Runnable() {
@Override
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
secs = (int) (updatedTime / 1000);
mins = secs / 60;
secs = secs % 60;
milliseconds = (int) (updatedTime % 1000);
if(secs==0 ){
Log.v("__in__if_secs_____", "_______"+secs);
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(this,1000);
logd.append("\nWrite at Time:"+secs+" secs"+milliseconds+" milliseconds");
}
else if(secs==1 ){
Log.v("__in__if_secs_____", "_______"+secs);
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==2 ){
Log.v("__in__if_secs_____", "_______"+secs);
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(updateTimerThread,1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==3 ){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==4 ){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\nWrite at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==5 ){
Log.v("__in__if_secs_____", "_______"+secs);
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\nWrite at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==6 ){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(updateTimerThread, 2000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==8 && milliseconds<500){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,2);
mBluetoothLeService.writeCharacteristic(val,1);
customHandler.postDelayed(updateTimerThread, 500);
logd.append("\nWrite at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==8 && milliseconds>=500){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 2000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==10 ){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 600);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==11 ){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 2200);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==13 && milliseconds<500 ){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 500);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
// 3rd
else if(secs==13 && milliseconds>=500 ){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==14 ){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==15 ){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==16 ){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==17 ){
byte[] val={1};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread, 1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs==18 ){
byte[] val={0};
mBluetoothLeService.writeCharacteristic(val,1);
mBluetoothLeService.writeCharacteristic(val,2);
customHandler.postDelayed(updateTimerThread,1000);
logd.append("\n Write at Time:"+secs+" secs "+milliseconds+" milliseconds");
}
else if(secs<19) {
customHandler.postDelayed(updateTimerThread, 0);
}
else if(secs==19) {
startTime = SystemClock.uptimeMillis();
Thread.currentThread().interrupt();
}
}
};
只有一个蓝牙服务正在写其他不是。在上面的代码中,runnale将继续运行长达19秒,但只有一个蓝牙服务端口正在写其他没有写但我得到的结果在logcat中为true.why.please解决这个问题。