mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-10-07 13:39:45 +02: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.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -287,17 +288,23 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
|||||||
private void startBTLEDiscovery() {
|
private void startBTLEDiscovery() {
|
||||||
Log.i(TAG, "Starting BTLE Discovery");
|
Log.i(TAG, "Starting BTLE Discovery");
|
||||||
handler.removeMessages(0, stopRunnable);
|
handler.removeMessages(0, stopRunnable);
|
||||||
handler.postDelayed(stopRunnable, SCAN_DURATION);
|
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
|
||||||
adapter.startLeScan(leScanCallback);
|
adapter.startLeScan(leScanCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBTDiscovery() {
|
private void startBTDiscovery() {
|
||||||
Log.i(TAG, "Starting BT Discovery");
|
Log.i(TAG, "Starting BT Discovery");
|
||||||
handler.removeMessages(0, stopRunnable);
|
handler.removeMessages(0, stopRunnable);
|
||||||
handler.postDelayed(stopRunnable, SCAN_DURATION);
|
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
|
||||||
adapter.startDiscovery();
|
adapter.startDiscovery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Message getPostMessage(Runnable runnable) {
|
||||||
|
Message m = Message.obtain(handler, runnable);
|
||||||
|
m.obj = runnable;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
DeviceCandidate deviceCandidate = deviceCandidates.get(position);
|
DeviceCandidate deviceCandidate = deviceCandidates.get(position);
|
||||||
@ -322,7 +329,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
|
|||||||
bondingAddress = btDevice.getAddress();
|
bondingAddress = btDevice.getAddress();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Log.e(TAG, "Error pairing device: " + deviceCandidate.getMacAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user