diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf7e825..0774d17a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ###Changelog +####Version 0.1.2 +* Added option to start Gadgetbridge and connect automatically when bluetooth is turned on + ####Version 0.1.1 * Fixed various bugs regarding K-9 Mail notifications. * "Generic notification support" in Setting now opens Androids "Notifcaion access" dialog. diff --git a/README.md b/README.md index 14a9fef2..000ac913 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,6 @@ How to use: Known Issues: * No reconnect, if connection is lost, you have to press "connect" again -* Notifications are not properly queued, if two arrive at about the same time, - one of them might get lost (TODO: confirm) * Android 4.4+ only, we can only change this by not handling generic notifications or by using AccessibiltyService. Don't know if it is worth the hassle. diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6f4bd216..a85e9fef 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,6 @@ android:label="@string/app_name"> - @@ -60,7 +59,6 @@ android:enabled="false"> - @@ -71,7 +69,11 @@ - + + + + + diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java index 27387d13..0b9b2b1f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothCommunicationService.java @@ -138,6 +138,10 @@ public class BluetoothCommunicationService extends Service { public int onStartCommand(Intent intent, int flags, int startId) { String action = intent.getAction(); + if (action == null) { + Log.i(TAG, "no action"); + return START_NOT_STICKY; + } if (!mStarted && !action.equals(ACTION_START)) { // using the service before issuing ACTION_START @@ -172,8 +176,7 @@ public class BluetoothCommunicationService extends Service { } if (btDeviceAddress == null) { Toast.makeText(this, "No supported device paired", Toast.LENGTH_SHORT).show(); - } - else if (mBtSocket == null || !mBtSocket.isConnected()) { + } else if (mBtSocket == null || !mBtSocket.isConnected()) { // currently only one thread allowed if (mBtSocketIoThread != null) { mBtSocketIoThread.quit(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothStateChangeReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothStateChangeReceiver.java new file mode 100644 index 00000000..67627487 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/BluetoothStateChangeReceiver.java @@ -0,0 +1,31 @@ +package nodomain.freeyourgadget.gadgetbridge; + +import android.bluetooth.BluetoothAdapter; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +public class BluetoothStateChangeReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + + if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { + if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); + if (!sharedPrefs.getBoolean("general_autoconnectonbluetooth", false)) { + return; + } + Intent startIntent = new Intent(context, BluetoothCommunicationService.class); + startIntent.setAction(BluetoothCommunicationService.ACTION_START); + context.startService(startIntent); + + Intent connectIntent = new Intent(context, BluetoothCommunicationService.class); + connectIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT); + context.startService(connectIntent); + } + } + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java index 23403f58..4279a7b5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/ControlCenter.java @@ -49,7 +49,6 @@ public class ControlCenter extends Activity { }); /* * Ask for permission to intercept notifications on first run. - * TODO: allow re-request in preferences */ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPrefs.getBoolean("firstrun", true)) { diff --git a/app/src/main/res/values/strings_activity_settings.xml b/app/src/main/res/values/strings_activity_settings.xml index 4d153bc6..30093888 100644 --- a/app/src/main/res/values/strings_activity_settings.xml +++ b/app/src/main/res/values/strings_activity_settings.xml @@ -2,6 +2,7 @@ General Settings + Connect to device when Bluetooth turned on Notifications diff --git a/app/src/main/res/values/styles.xml~ b/app/src/main/res/values/styles.xml~ new file mode 100644 index 00000000..766ab993 --- /dev/null +++ b/app/src/main/res/values/styles.xml~ @@ -0,0 +1,8 @@ + + + + + + diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 2288e828..6a145307 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -1,3 +1,7 @@ +