mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-30 22:12:55 +01:00
Fix removal of async runnable to stop pairing after 60s (#3)
This commit is contained in:
parent
b25da80656
commit
84d1e95767
@ -10,6 +10,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -287,17 +288,23 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
private void startBTLEDiscovery() {
|
||||
Log.i(TAG, "Starting BTLE Discovery");
|
||||
handler.removeMessages(0, stopRunnable);
|
||||
handler.postDelayed(stopRunnable, SCAN_DURATION);
|
||||
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
|
||||
adapter.startLeScan(leScanCallback);
|
||||
}
|
||||
|
||||
private void startBTDiscovery() {
|
||||
Log.i(TAG, "Starting BT Discovery");
|
||||
handler.removeMessages(0, stopRunnable);
|
||||
handler.postDelayed(stopRunnable, SCAN_DURATION);
|
||||
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
|
||||
adapter.startDiscovery();
|
||||
}
|
||||
|
||||
private Message getPostMessage(Runnable runnable) {
|
||||
Message m = Message.obtain(handler, runnable);
|
||||
m.obj = runnable;
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
DeviceCandidate deviceCandidate = deviceCandidates.get(position);
|
||||
@ -322,7 +329,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
||||
bondingAddress = btDevice.getAddress();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Error pairing device: " + deviceCandidate.getMacAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user