1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-08-30 19:15:54 +02:00

* Add option to start Gadgetbridge and connect automatically when bluetooth is turned on.

This closes #9
This commit is contained in:
Andreas Shimokawa 2015-03-17 21:41:58 +01:00
parent 0f3cd9b7c7
commit c56194c0e5
9 changed files with 57 additions and 8 deletions

View File

@ -1,5 +1,8 @@
###Changelog ###Changelog
####Version 0.1.2
* Added option to start Gadgetbridge and connect automatically when bluetooth is turned on
####Version 0.1.1 ####Version 0.1.1
* Fixed various bugs regarding K-9 Mail notifications. * Fixed various bugs regarding K-9 Mail notifications.
* "Generic notification support" in Setting now opens Androids "Notifcaion access" dialog. * "Generic notification support" in Setting now opens Androids "Notifcaion access" dialog.

View File

@ -27,8 +27,6 @@ How to use:
Known Issues: Known Issues:
* No reconnect, if connection is lost, you have to press "connect" again * 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 * 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 notifications or by using AccessibiltyService. Don't know if it is worth the
hassle. hassle.

View File

@ -23,7 +23,6 @@
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
@ -60,7 +59,6 @@
android:enabled="false"> android:enabled="false">
<intent-filter> <intent-filter>
<data android:scheme="email" /> <data android:scheme="email" />
<action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" /> <action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
@ -71,7 +69,11 @@
<action android:name="com.andrew.apollo.metachanged" /> <action android:name="com.andrew.apollo.metachanged" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".BluetoothStateChangeReceiver">
<intent-filter>
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
<receiver android:name=".StopServiceReceiver" /> <receiver android:name=".StopServiceReceiver" />
<receiver android:name=".GBMusicControlReceiver"> <receiver android:name=".GBMusicControlReceiver">
<intent-filter> <intent-filter>

View File

@ -138,6 +138,10 @@ public class BluetoothCommunicationService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent.getAction(); String action = intent.getAction();
if (action == null) {
Log.i(TAG, "no action");
return START_NOT_STICKY;
}
if (!mStarted && !action.equals(ACTION_START)) { if (!mStarted && !action.equals(ACTION_START)) {
// using the service before issuing ACTION_START // using the service before issuing ACTION_START
@ -172,8 +176,7 @@ public class BluetoothCommunicationService extends Service {
} }
if (btDeviceAddress == null) { if (btDeviceAddress == null) {
Toast.makeText(this, "No supported device paired", Toast.LENGTH_SHORT).show(); 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 // currently only one thread allowed
if (mBtSocketIoThread != null) { if (mBtSocketIoThread != null) {
mBtSocketIoThread.quit(); mBtSocketIoThread.quit();

View File

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

View File

@ -49,7 +49,6 @@ public class ControlCenter extends Activity {
}); });
/* /*
* Ask for permission to intercept notifications on first run. * Ask for permission to intercept notifications on first run.
* TODO: allow re-request in preferences
*/ */
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPrefs.getBoolean("firstrun", true)) { if (sharedPrefs.getBoolean("firstrun", true)) {

View File

@ -2,6 +2,7 @@
<!-- Strings related to Settings --> <!-- Strings related to Settings -->
<string name="pref_header_general">General Settings</string> <string name="pref_header_general">General Settings</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to device when Bluetooth turned on</string>
<!-- Strings related to Notifications --> <!-- Strings related to Notifications -->
<string name="pref_header_notifications">Notifications</string> <string name="pref_header_notifications">Notifications</string>

View File

@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -1,3 +1,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="false"
android:key="general_autoconnectonbluetooth"
android:title="@string/pref_title_general_autoconnectonbluetooth" />
</PreferenceScreen> </PreferenceScreen>