1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-02 09:46:24 +02:00

Fix removal of async runnable to stop pairing after 60s (#3)

This commit is contained in:
cpfeiffer 2015-05-10 23:14:32 +02:00
parent b25da80656
commit 84d1e95767

View File

@ -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());
} }
} }
} }