(오디오가 아닌) 장치와의 블루투스 연결이 끊어져도 안정적으로 감지 할 수 있는지 알아 내려고하고 있습니다. 내가 스레드를 시작하고 응용 프로그램을 (이 서비스는 백그라운드에서 실행) 사용하지 않고 나중에 12 시간 장치를 분리 할 때블루투스 장치 연결이 끊어졌습니다.
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}
어떻게 신뢰할 수있는 것은이 방법입니다 : 안드로이드 SDK는이 조각을 사용하는 블루투스 채팅 예제를 제공합니다. 이 서비스는 항상 사기 당할 수 있습니까?
그런 다음 방송이 있습니다. 내 앱에서 항상 이러한 브로드 캐스트를 수신합니까? 언제 그럴 거지? 나는 AndroidManifest를이를 사용하여 해당 구현을 시도했다 :
<receiver android:name="MyReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>
나는 짧은 시간에 방법, 두 작업 모두를 테스트했습니다. 이전에 말했듯이, 전화기가 오랫동안 유휴 상태 일 때 이들이 신뢰할 수 있는지 확실하지 않습니다.
누가이 문제에 관해 밝힐 수 있습니까?