https://github.com/NordicPlayground/Android-nRF-UART
해당 소스를 보며 BLE 통신을 공부하고 있습니다.
listView로 값들을 읽어오는데, 거의 0.01초 간격으로 값들이 갱신됩니다.
1초나 5초 간격으로 값을 확인하고 싶은데, delay를 넣으면 실행이 안되어요..ㅠ
어떻게 해야할까요..ㅠㅠ
private final BroadcastReceiver UARTStatusChangeReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
final Intent mIntent = intent;
//*********************//
if (action.equals(UartService.ACTION_GATT_CONNECTED)) {
runOnUiThread(new Runnable() {
public void run() {
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
Log.d(TAG, "UART_CONNECT_MSG");
btnConnectDisconnect.setText("Disconnect");
((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName());
Toast.makeText(getApplicationContext(), "Connected to: "+ mDevice.getName(), Toast.LENGTH_LONG).show();
mState = UART_PROFILE_CONNECTED;
}
});
}
//*********************//
if (action.equals(UartService.ACTION_GATT_DISCONNECTED)) {
runOnUiThread(new Runnable() {
public void run() {
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
Log.d(TAG, "UART_DISCONNECT_MSG");
btnConnectDisconnect.setText("Connect");
((TextView) findViewById(R.id.deviceName)).setText("Not Connected");
Toast.makeText(getApplicationContext(), "Disconnected to: "+ mDevice.getName(), Toast.LENGTH_LONG).show();
mState = UART_PROFILE_DISCONNECTED;
mService.close();
}
});
}
//*********************//
if (action.equals(UartService.ACTION_GATT_SERVICES_DISCOVERED)) {
mService.enableTXNotification();
}
//*********************//
if (action.equals(UartService.ACTION_DATA_AVAILABLE)) {
final byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA);
runOnUiThread(new Runnable() {
public void run() {
try {
String text = new BigInteger(1, txValue).toString(16);
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
listAdapter.add("["+currentDateTimeString+"] RX: "+text);
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
});
}
//*********************//
if (action.equals(UartService.DEVICE_DOES_NOT_SUPPORT_UART)){
showMessage("Device doesn't support UART. Disconnecting");
mService.disconnect();
}
}
};