2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-02 15:15:09 +00:00

Catch BackgroundServiceStartNotAllowedException

This commit is contained in:
Albert Vaca Cintora
2023-05-26 20:21:40 +02:00
parent 9e39cbd979
commit c70d03dbe8

View File

@@ -41,7 +41,6 @@ public class RunCommandWidget extends AppWidgetProvider {
if (plugin != null) { if (plugin != null) {
try { try {
plugin.runCommand(targetCommand); plugin.runCommand(targetCommand);
} catch (Exception ex) { } catch (Exception ex) {
Log.e("RunCommandWidget", "Error running command", ex); Log.e("RunCommandWidget", "Error running command", ex);
@@ -51,10 +50,14 @@ public class RunCommandWidget extends AppWidgetProvider {
setCurrentDevice(context); setCurrentDevice(context);
} }
try {
// FIXME: Remove the need for a background service, we are not allowed to start them in API 31+
final Intent newIntent = new Intent(context, RunCommandWidgetDataProviderService.class); final Intent newIntent = new Intent(context, RunCommandWidgetDataProviderService.class);
context.startService(newIntent); context.startService(newIntent);
updateWidget(context); updateWidget(context);
} catch(IllegalStateException exception) { // Meant to catch BackgroundServiceStartNotAllowedException on API 31+
exception.printStackTrace();
}
} }
private void setCurrentDevice(final Context context) { private void setCurrentDevice(final Context context) {