Added option to start on boot (fixes #19).
This does not trigger the "enable Bluetooth" dialog, which means Bluetooth won't be enabled. Even if Bluetooth was already active, we might not have the necessary permissions. Internet will work fine though.
This commit is contained in:
parent
6867b19380
commit
28cb4f15d9
4 changed files with 32 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
|
||||
|
||||
|
@ -51,6 +52,12 @@
|
|||
android:value=".activities.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<receiver android:name=".service.BootReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name=".service.ChatService" />
|
||||
|
||||
</application>
|
||||
|
|
|
@ -78,6 +78,9 @@
|
|||
<!-- Preference title -->
|
||||
<string name="scan_interval_seconds">Scan Interval (seconds)</string>
|
||||
|
||||
<!-- Preference title -->
|
||||
<string name="start_on_boot">Start on Boot</string>
|
||||
|
||||
<!-- Preference title -->
|
||||
<string name="notification_sounds">Notification Sounds</string>
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
android:key="user_status"
|
||||
android:inputType="textCapSentences" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:title="@string/start_on_boot"
|
||||
android:key="start_on_boot" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:title="@string/notification_sounds"
|
||||
android:key="notification_sounds" />
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.nutomic.ensichat.service
|
||||
|
||||
import android.content.{Intent, Context, BroadcastReceiver}
|
||||
import android.preference.PreferenceManager
|
||||
|
||||
/**
|
||||
* Starts [[ChatService]] on boot if preference is enabled.
|
||||
*/
|
||||
class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
override def onReceive(context: Context, intent: Intent): Unit = {
|
||||
val sp = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (sp.getBoolean("start_on_boot", false)) {
|
||||
context.startService(new Intent(context, classOf[ChatService]))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue