always save last device address when connecting, fixes #258
This commit is contained in:
parent
f046e66bf1
commit
76fc7a2aec
|
@ -164,6 +164,7 @@ public class DeviceCommunicationService extends Service {
|
||||||
|
|
||||||
// when we get past this, we should have valid mDeviceSupport and mGBDevice instances
|
// when we get past this, we should have valid mDeviceSupport and mGBDevice instances
|
||||||
|
|
||||||
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_START:
|
case ACTION_START:
|
||||||
start();
|
start();
|
||||||
|
@ -171,19 +172,21 @@ public class DeviceCommunicationService extends Service {
|
||||||
case ACTION_CONNECT:
|
case ACTION_CONNECT:
|
||||||
start(); // ensure started
|
start(); // ensure started
|
||||||
GBDevice gbDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
GBDevice gbDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||||
|
String btDeviceAddress = null;
|
||||||
if (gbDevice == null) {
|
if (gbDevice == null) {
|
||||||
String btDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
|
btDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
if (btDeviceAddress == null && sharedPrefs != null) { // may be null in test cases
|
||||||
if (sharedPrefs != null) { // may be null in test cases
|
|
||||||
if (btDeviceAddress == null) {
|
|
||||||
btDeviceAddress = sharedPrefs.getString("last_device_address", null);
|
btDeviceAddress = sharedPrefs.getString("last_device_address", null);
|
||||||
} else {
|
|
||||||
sharedPrefs.edit().putString("last_device_address", btDeviceAddress).apply();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (btDeviceAddress != null) {
|
if (btDeviceAddress != null) {
|
||||||
gbDevice = DeviceHelper.getInstance().findAvailableDevice(btDeviceAddress, this);
|
gbDevice = DeviceHelper.getInstance().findAvailableDevice(btDeviceAddress, this);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
btDeviceAddress = gbDevice.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sharedPrefs != null) {
|
||||||
|
sharedPrefs.edit().putString("last_device_address", btDeviceAddress).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gbDevice != null && !isConnecting() && !isConnected()) {
|
if (gbDevice != null && !isConnecting() && !isConnected()) {
|
||||||
|
@ -232,7 +235,6 @@ public class DeviceCommunicationService extends Service {
|
||||||
if (((notificationSpec.flags & NotificationSpec.FLAG_WEARABLE_REPLY) > 0)
|
if (((notificationSpec.flags & NotificationSpec.FLAG_WEARABLE_REPLY) > 0)
|
||||||
|| (notificationSpec.type == NotificationType.SMS && notificationSpec.phoneNumber != null)) {
|
|| (notificationSpec.type == NotificationType.SMS && notificationSpec.phoneNumber != null)) {
|
||||||
// NOTE: maybe not where it belongs
|
// NOTE: maybe not where it belongs
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
if (sharedPrefs.getBoolean("pebble_force_untested", false)) {
|
if (sharedPrefs.getBoolean("pebble_force_untested", false)) {
|
||||||
// I would rather like to save that as an array in ShadredPreferences
|
// I would rather like to save that as an array in ShadredPreferences
|
||||||
// this would work but I dont know how to do the same in the Settings Activity's xml
|
// this would work but I dont know how to do the same in the Settings Activity's xml
|
||||||
|
|
Loading…
Reference in New Issue