diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-11-08 21:53:50 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-11-08 22:09:49 +0100 |
commit | 4b0ca9038bab18aeec525de42a295345c0acfc0a (patch) | |
tree | c71340584ae9b3055b6abc0b7978ce720ab251ce /src/main/java/de/pixart | |
parent | 771d214c84a217799b405534f23faa23dfec043d (diff) |
start ExportLogsService correctly on devices >= OREO
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/AlarmReceiver.java | 13 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/SettingsActivity.java | 11 |
2 files changed, 21 insertions, 3 deletions
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) { |