Automatically start the service on boot (can be turned off)

Fixes #9
master
cpfeiffer 2017-02-17 23:11:44 +01:00
parent 23f2dd35d4
commit e5d09b9fa2
5 changed files with 40 additions and 0 deletions

View File

@ -17,6 +17,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature
android:name="android.hardware.bluetooth"
@ -225,6 +226,14 @@
</intent-filter>
</activity>
<receiver android:name=".externalevents.AutoStartReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:name=".externalevents.BluetoothStateChangeReceiver"
android:exported="false">

View File

@ -0,0 +1,20 @@
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
public class AutoStartReceiver extends BroadcastReceiver {
private static final String TAG = AutoStartReceiver.class.getName();
@Override
public void onReceive(Context context, Intent intent) {
if (GBApplication.getGBPrefs().getAutoStart()) {
Log.i(TAG, "Boot completed, starting Gadgetbridge");
GBApplication.deviceService().start();
}
}
}

View File

@ -6,6 +6,8 @@ import java.util.Date;
public class GBPrefs {
public static final String AUTO_RECONNECT = "general_autocreconnect";
private static final String AUTO_START = "general_autostartonboot";
private static final boolean AUTO_START_DEFAULT = true;
public static boolean AUTO_RECONNECT_DEFAULT = true;
public static final String USER_NAME = "mi_user_alias";
@ -22,6 +24,10 @@ public class GBPrefs {
return mPrefs.getBoolean(AUTO_RECONNECT, AUTO_RECONNECT_DEFAULT);
}
public boolean getAutoStart() {
return mPrefs.getBoolean(AUTO_START, AUTO_START_DEFAULT);
}
public String getUserName() {
return mPrefs.getString(USER_NAME, USER_NAME_DEFAULT);
}

View File

@ -52,6 +52,7 @@
<string name="pref_header_general">General Settings</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to device when Bluetooth turned on</string>
<string name="pref_title_general_autostartonboot">Start automatically</string>
<string name="pref_title_general_autocreonnect">Reconnect automatically</string>
<string name="pref_title_audo_player">Preferred Audioplayer</string>
<string name="pref_default">Default</string>

View File

@ -3,6 +3,10 @@
<PreferenceCategory
android:key="pref_key_general"
android:title="@string/pref_header_general">
<CheckBoxPreference
android:defaultValue="true"
android:key="general_autostartonboot"
android:title="@string/pref_title_general_autostartonboot" />
<CheckBoxPreference
android:defaultValue="false"
android:key="general_autoconnectonbluetooth"