From 4b0ca9038bab18aeec525de42a295345c0acfc0a Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 8 Nov 2018 21:53:50 +0100 Subject: start ExportLogsService correctly on devices >= OREO --- .../java/de/pixart/messenger/services/AlarmReceiver.java | 13 +++++++++++-- src/main/java/de/pixart/messenger/ui/SettingsActivity.java | 11 ++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/pixart') diff --git a/src/main/java/de/pixart/messenger/services/AlarmReceiver.java b/src/main/java/de/pixart/messenger/services/AlarmReceiver.java index e20b567dd..e4c07366d 100644 --- a/src/main/java/de/pixart/messenger/services/AlarmReceiver.java +++ b/src/main/java/de/pixart/messenger/services/AlarmReceiver.java @@ -3,9 +3,11 @@ package de.pixart.messenger.services; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.support.v4.content.ContextCompat; import android.util.Log; import de.pixart.messenger.Config; +import de.pixart.messenger.utils.Compatibility; public class AlarmReceiver extends BroadcastReceiver { public static final int SCHEDULE_ALARM_REQUEST_CODE = 523976483; @@ -14,8 +16,15 @@ public class AlarmReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { if (intent.getAction().contains("exportlogs")) { Log.d(Config.LOGTAG, "Received alarm broadcast to export logs"); - Intent i = new Intent(context, ExportLogsService.class); - context.startService(i); + try { + if (Compatibility.runsAndTargetsTwentySix(context)) { + ContextCompat.startForegroundService(context, new Intent(context, ExportLogsService.class)); + } else { + context.startService(new Intent(context, ExportLogsService.class)); + } + } catch (RuntimeException e) { + Log.d(Config.LOGTAG, "AlarmReceiver was unable to start ExportLogsService"); + } } } } diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 1c0992cf1..5d3b0cfd7 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -39,6 +39,7 @@ import de.pixart.messenger.entities.Account; import de.pixart.messenger.services.ExportLogsService; import de.pixart.messenger.services.MemorizingTrustManager; import de.pixart.messenger.ui.util.StyledAttributes; +import de.pixart.messenger.utils.Compatibility; import de.pixart.messenger.utils.TimeframeUtils; import rocks.xmpp.addr.Jid; @@ -547,7 +548,15 @@ public class SettingsActivity extends XmppActivity implements } private void startExport() { - ContextCompat.startForegroundService(this, new Intent(this, ExportLogsService.class)); + try { + if (Compatibility.runsAndTargetsTwentySix(this)) { + ContextCompat.startForegroundService(this, new Intent(this, ExportLogsService.class)); + } else { + this.startService(new Intent(this, ExportLogsService.class)); + } + } catch (RuntimeException e) { + Log.d(Config.LOGTAG, "SettingsActivity was unable to start ExportLogsService"); + } } private void displayToast(final String msg) { -- cgit v1.2.3