mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +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() {
|
private boolean needPreConfiguration() {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
if (!context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName())) {
|
return !context.getSystemService(PowerManager.class).isIgnoringBatteryOptimizations(context.getPackageName());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -20,6 +21,8 @@ import org.communiquons.comunic.MainActivity;
|
|||||||
import org.communiquons.comunic.R;
|
import org.communiquons.comunic.R;
|
||||||
|
|
||||||
public class NotificationsService extends Service {
|
public class NotificationsService extends Service {
|
||||||
|
private static final String TAG = NotificationsService.class.getSimpleName();
|
||||||
|
|
||||||
public static final String CHANNEL_ID = "IndependentPushServiceChannel";
|
public static final String CHANNEL_ID = "IndependentPushServiceChannel";
|
||||||
private static final String INDEPENDENT_PUSH_NOTIFICATIONS_SERVICE = "independent-push-notifications-service";
|
private static final String INDEPENDENT_PUSH_NOTIFICATIONS_SERVICE = "independent-push-notifications-service";
|
||||||
private static final String WS_URL_PREF_KEY = "ws_url";
|
private static final String WS_URL_PREF_KEY = "ws_url";
|
||||||
@ -73,9 +76,9 @@ public class NotificationsService extends Service {
|
|||||||
.setContentIntent(pendingIntent)
|
.setContentIntent(pendingIntent)
|
||||||
.build();
|
.build();
|
||||||
startForeground(1, notification);
|
startForeground(1, notification);
|
||||||
|
|
||||||
initService();
|
initService();
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,11 +99,17 @@ public class NotificationsService extends Service {
|
|||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
Log.v(TAG, "Destroying service");
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
private void initService() {
|
private void initService() {
|
||||||
String url = getSharedPreferences(INDEPENDENT_PUSH_NOTIFICATIONS_SERVICE, MODE_PRIVATE)
|
String url = getSharedPreferences(INDEPENDENT_PUSH_NOTIFICATIONS_SERVICE, MODE_PRIVATE)
|
||||||
.getString(WS_URL_PREF_KEY, null);
|
.getString(WS_URL_PREF_KEY, null);
|
||||||
|
|
||||||
System.out.println("START HEAVY WORK HERE !!!!");
|
System.out.println("START HEAVY WORK HERE !!!!");
|
||||||
System.out.println("Connect to " + url);
|
System.out.println("Connect to " + url);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user