1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-22 22:43:22 +00:00

Background service works

This commit is contained in:
Pierre HUBERT 2021-04-14 18:14:08 +02:00
parent bf53babf53
commit 752cdb04a5
2 changed files with 14 additions and 7 deletions

View File

@ -52,9 +52,7 @@ public class NotificationsChannel implements MethodChannel.MethodCallHandler {
private boolean needPreConfiguration() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
return true;
}
return !context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName());
}
return false;
}

View File

@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -20,6 +21,8 @@ import org.communiquons.comunic.MainActivity;
import org.communiquons.comunic.R;
public class NotificationsService extends Service {
private static final String TAG = NotificationsService.class.getSimpleName();
public static final String CHANNEL_ID = "IndependentPushServiceChannel";
private static final String INDEPENDENT_PUSH_NOTIFICATIONS_SERVICE = "independent-push-notifications-service";
private static final String WS_URL_PREF_KEY = "ws_url";
@ -73,9 +76,9 @@ public class NotificationsService extends Service {
.setContentIntent(pendingIntent)
.build();
startForeground(1, notification);
initService();
return START_STICKY;
}
@ -96,11 +99,17 @@ public class NotificationsService extends Service {
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
Log.v(TAG, "Destroying service");
super.onDestroy();
}
private void initService() {
String url = getSharedPreferences(INDEPENDENT_PUSH_NOTIFICATIONS_SERVICE, MODE_PRIVATE)
.getString(WS_URL_PREF_KEY, null);
System.out.println("START HEAVY WORK HERE !!!!");
System.out.println("Connect to " + url);
}