mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-21 20:39:22 +00:00
Background service works
This commit is contained in:
parent
bf53babf53
commit
752cdb04a5
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user