Merge pull request #32 from schwma/start-on-boot

Start Gotify WebSocketService on boot completed
This commit is contained in:
Jannis Mattheis
2018-12-22 11:58:51 +01:00
committed by GitHub
2 changed files with 33 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application <application
android:allowBackup="false" android:allowBackup="false"
@@ -40,6 +41,12 @@
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar" />
<service android:name=".service.WebSocketService" /> <service android:name=".service.WebSocketService" />
<receiver android:name=".init.BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>

View File

@@ -0,0 +1,26 @@
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 {
@Override
public void onReceive(Context context, Intent intent) {
Settings 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));
}
}
}