From e8690ca28b54c8117fcaa1853156a9dd0f365cf1 Mon Sep 17 00:00:00 2001
From: Marcel Schwarz <37244550+schwma@users.noreply.github.com>
Date: Wed, 12 Dec 2018 20:34:56 +0100
Subject: [PATCH] Start Gotify WebSocketService on boot completed
---
app/src/main/AndroidManifest.xml | 7 +++++
.../gotify/init/BootCompletedReceiver.java | 28 +++++++++++++++++++
2 files changed, 35 insertions(+)
create mode 100644 app/src/main/java/com/github/gotify/init/BootCompletedReceiver.java
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 26f9b7c..b1ae700 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/github/gotify/init/BootCompletedReceiver.java b/app/src/main/java/com/github/gotify/init/BootCompletedReceiver.java
new file mode 100644
index 0000000..6eb519f
--- /dev/null
+++ b/app/src/main/java/com/github/gotify/init/BootCompletedReceiver.java
@@ -0,0 +1,28 @@
+package com.github.gotify.init;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import com.github.gotify.Settings;
+import com.github.gotify.service.WebSocketService;
+
+public class BootCompletedReceiver extends BroadcastReceiver {
+
+ private Settings settings;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ settings = new Settings(context);
+
+ if (!settings.tokenExists()) {
+ return;
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ context.startForegroundService(new Intent(context, WebSocketService.class));
+ } else {
+ context.startService(new Intent(context, WebSocketService.class));
+ }
+ }
+}