2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

Fix crash on start in API 31+

Sometimes we can't start the foreground service at boot for some reason.
I have a couple untested theories: either the phone is slow at boot and
we don't get to call startForeground in time, or the user has never
started the app before and we are not allowed to start it or to create a
notification.
This commit is contained in:
Albert Vaca Cintora
2023-07-29 11:22:23 +02:00
parent b00a0771fd
commit 4da0599f0e

View File

@@ -28,7 +28,12 @@ public class KdeConnectBroadcastReceiver extends BroadcastReceiver {
break;
case Intent.ACTION_BOOT_COMPLETED:
Log.i("KdeConnect", "KdeConnectBroadcastReceiver");
BackgroundService.Start(context);
try {
BackgroundService.Start(context);
} catch (IllegalStateException e) { // To catch ForegroundServiceStartNotAllowedException
Log.w("BroadcastReceiver", "Couldn't start the foreground service.");
e.printStackTrace();
}
break;
case WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION:
case WifiManager.WIFI_STATE_CHANGED_ACTION: