mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Start push notifications service when starting the application
This commit is contained in:
		@@ -4,6 +4,7 @@ package org.communiquons.comunic;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
 | 
			
		||||
import org.communiquons.comunic.independentnotifications.NotificationsChannel;
 | 
			
		||||
import org.communiquons.comunic.independentnotifications.NotificationsService;
 | 
			
		||||
 | 
			
		||||
import io.flutter.embedding.android.FlutterActivity;
 | 
			
		||||
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";
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onStart() {
 | 
			
		||||
        super.onStart();
 | 
			
		||||
        NotificationsService.startService(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
 | 
			
		||||
        super.configureFlutterEngine(flutterEngine);
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ public class NotificationsService extends Service implements Runnable {
 | 
			
		||||
    private static final int NOTIFS_ID = 10;
 | 
			
		||||
 | 
			
		||||
    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 Thread thread;
 | 
			
		||||
@@ -90,6 +90,12 @@ public class NotificationsService extends Service implements Runnable {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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();
 | 
			
		||||
 | 
			
		||||
        Intent notificationIntent = new Intent(this, MainActivity.class);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user