Start Gotify WebSocketService on boot completed
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user