1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Start push notifications service when starting the application

This commit is contained in:
Pierre HUBERT 2021-04-16 11:07:22 +02:00
parent efe60a63de
commit f995003306
2 changed files with 14 additions and 1 deletions

View File

@ -4,6 +4,7 @@ package org.communiquons.comunic;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.communiquons.comunic.independentnotifications.NotificationsChannel; import org.communiquons.comunic.independentnotifications.NotificationsChannel;
import org.communiquons.comunic.independentnotifications.NotificationsService;
import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
@ -13,6 +14,12 @@ public class MainActivity extends FlutterActivity {
private static final String INDEPENDENT_NOTIFICATIONS_CHANNEL = "org.communiquons.comunic/independent-push-notifications-service"; private static final String INDEPENDENT_NOTIFICATIONS_CHANNEL = "org.communiquons.comunic/independent-push-notifications-service";
@Override
protected void onStart() {
super.onStart();
NotificationsService.startService(this);
}
@Override @Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine); super.configureFlutterEngine(flutterEngine);

View File

@ -44,7 +44,7 @@ public class NotificationsService extends Service implements Runnable {
private static final int NOTIFS_ID = 10; private static final int NOTIFS_ID = 10;
private static final int CONNECT_TIMEOUT = 1000; private static final int CONNECT_TIMEOUT = 1000;
private static final int RECONNECT_INTERVAL = 10000; private static final int RECONNECT_INTERVAL = 60000;
private static final int PING_INTERVAL = 15000; private static final int PING_INTERVAL = 15000;
private Thread thread; private Thread thread;
@ -90,6 +90,12 @@ public class NotificationsService extends Service implements Runnable {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (thread != null) {
System.out.println("The service has already been started. Skipping initialization...");
return START_STICKY;
}
createServiceNotificationChannel(); createServiceNotificationChannel();
Intent notificationIntent = new Intent(this, MainActivity.class); Intent notificationIntent = new Intent(this, MainActivity.class);