我的问题是:当我使用Arduino和HC 06蓝牙模块从arduino收到特定消息时,我尝试制作一个自动运行的秒表。我已经完成了Android程序。我无法使用来自蓝牙的消息。我收到一条消息(我的消息是“ 7”和“ 9”)。 if(value ==“ 7”)我不知道在哪里以及如何使用它。当我尝试将readMessage转换为整数时,程序无法打开并返回错误
mHandler = new Handler(){
public void handleMessage(android.os.Message msg){
String readMessage = null;
if(msg.what == MESSAGE_READ){
try {
readMessage = new String((byte[]) msg.obj, "UTF-8");
deger= readMessage;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mReadBuffer.setText(readMessage);
}
if(msg.what == CONNECTING_STATUS){
if(msg.arg1 == 1)
mBluetoothStatus.setText("Cihaza Bağlandı: " + (String)(msg.obj));
else
mBluetoothStatus.setText("Bağlantı Başarısız");
}
}
};
.
.
.
public void run() {
byte[] buffer = new byte[256];
int bytes;
while (true) {
try {
bytes = mmInStream.read(buffer);
if(bytes != 0) {
SystemClock.sleep(1000);
bytes = mmInStream.available();
bytes = mmInStream.read(buffer, 0, bytes);
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
}
} catch (IOException e) {
e.printStackTrace();
break;
}
}
//not work
new Thread()
{
public void run()
{
if(deger=="7")
{
StartTime = SystemClock.uptimeMillis();
sHandler.postDelayed(runnable, 0);
reset.setEnabled(true);
}
}
}.start();
}
//not work
mHandler = new Handler(){
public void handleMessage(android.os.Message msg){
String readMessage = null;
if(msg.what == MESSAGE_READ){
try {
readMessage = new String((byte[]) msg.obj, "UTF-8");
readMessage;
if(readmessage=="7")
{
StartTime = SystemClock.uptimeMillis();
sHandler.postDelayed(runnable, 0);
reset.setEnabled(true);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mReadBuffer.setText(readMessage);
}
if(msg.what == CONNECTING_STATUS){
if(msg.arg1 == 1)
mBluetoothStatus.setText("Cihaza Bağlandı: " + (String)(msg.obj));
else
mBluetoothStatus.setText("Bağlantı Başarısız");
}
}
};