1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-02-17 12:56:48 +01:00

Try to refresh device list if BluetoothDevice.ACTION_BOND_STATE_CHANGED is received.

On my Android 4.4 device, this does not work however (no Intents arrive)
This commit is contained in:
Andreas Shimokawa 2015-05-10 16:56:09 +02:00
parent f101926186
commit 0d77a5ac05

View File

@ -45,25 +45,30 @@ public class ControlCenter extends Activity {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (action.equals(ACTION_QUIT)) { switch (action) {
finish(); case ACTION_QUIT:
} else if (action.equals(ACTION_REFRESH_DEVICELIST)) { finish();
refreshPairedDevices(); break;
} else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) { case ACTION_REFRESH_DEVICELIST:
GBDevice dev = intent.getParcelableExtra("device"); case BluetoothDevice.ACTION_BOND_STATE_CHANGED:
if (dev.getAddress() != null) { refreshPairedDevices();
int index = deviceList.indexOf(dev); // search by address break;
if (index >= 0) { case GBDevice.ACTION_DEVICE_CHANGED:
deviceList.set(index, dev); GBDevice dev = intent.getParcelableExtra("device");
} else { if (dev.getAddress() != null) {
deviceList.add(dev); int index = deviceList.indexOf(dev); // search by address
if (index >= 0) {
deviceList.set(index, dev);
} else {
deviceList.add(dev);
}
} }
} refreshPairedDevices();
refreshPairedDevices();
if (dev.isConnected() && dev.getFirmwareVersion() == null) { if (dev.isConnected() && dev.getFirmwareVersion() == null) {
requestDeviceInfo(); requestDeviceInfo();
} }
break;
} }
} }
}; };
@ -95,6 +100,7 @@ public class ControlCenter extends Activity {
filter.addAction(ACTION_QUIT); filter.addAction(ACTION_QUIT);
filter.addAction(ACTION_REFRESH_DEVICELIST); filter.addAction(ACTION_REFRESH_DEVICELIST);
filter.addAction(GBDevice.ACTION_DEVICE_CHANGED); filter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
refreshPairedDevices(); refreshPairedDevices();
@ -103,7 +109,7 @@ public class ControlCenter extends Activity {
*/ */
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPrefs.getBoolean("firstrun", true)) { if (sharedPrefs.getBoolean("firstrun", true)) {
sharedPrefs.edit().putBoolean("firstrun", false).commit(); sharedPrefs.edit().putBoolean("firstrun", false).apply();
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(enableIntent); startActivity(enableIntent);
} }