summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2023-12-14 11:16:55 +0100
committerThomas <tschneider.ac@gmail.com>2023-12-14 11:16:55 +0100
commitcfad7131d2c5ef61f26b4d2146c76c5d95dd3942 (patch)
treecf94da502cb43ff963e9592eb1fdfcf6608971ec
parentf0324038e369edaca5e0058537ba8c5cccda5ccf (diff)
Fix a crash
-rw-r--r--app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java b/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java
index e90bda3da..2411e4d23 100644
--- a/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java
+++ b/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java
@@ -23,6 +23,8 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ServiceInfo;
+import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@@ -52,7 +54,7 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
super.onCreate();
networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this);
- ContextCompat.registerReceiver(RetrieveInfoService.this, networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
+ ContextCompat.registerReceiver(RetrieveInfoService.this, networkStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
getString(R.string.notification_channel_name),
@@ -66,7 +68,11 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
.setContentText(getString(R.string.notification_channel_name))
.setAutoCancel(true).build();
- startForeground(1, notification);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
+ } else {
+ startForeground(1, notification);
+ }
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
@@ -77,7 +83,6 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
.setAutoCancel(true);
Notification notification = builder.build();
-
startForeground(1, notification);
}