mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix a crash
This commit is contained in:
parent
f0324038e3
commit
cfad7131d2
1 changed files with 8 additions and 3 deletions
|
@ -23,6 +23,8 @@ import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.pm.ServiceInfo;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
@ -52,7 +54,7 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
networkStateReceiver = new NetworkStateReceiver();
|
networkStateReceiver = new NetworkStateReceiver();
|
||||||
networkStateReceiver.addListener(this);
|
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) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
|
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
|
||||||
getString(R.string.notification_channel_name),
|
getString(R.string.notification_channel_name),
|
||||||
|
@ -66,7 +68,11 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
|
||||||
.setContentText(getString(R.string.notification_channel_name))
|
.setContentText(getString(R.string.notification_channel_name))
|
||||||
.setAutoCancel(true).build();
|
.setAutoCancel(true).build();
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
|
||||||
|
} else {
|
||||||
startForeground(1, notification);
|
startForeground(1, notification);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
|
||||||
|
@ -77,7 +83,6 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
|
||||||
.setAutoCancel(true);
|
.setAutoCancel(true);
|
||||||
|
|
||||||
Notification notification = builder.build();
|
Notification notification = builder.build();
|
||||||
|
|
||||||
startForeground(1, notification);
|
startForeground(1, notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue