mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 09:17:29 +01:00
Instead of crashing, display a notification that the service couldn't be started
This commit is contained in:
parent
97f4b275f7
commit
701039e673
@ -43,6 +43,7 @@ import android.provider.ContactsContract.PhoneLookup;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import java.io.File;
|
||||
@ -86,8 +87,9 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
|
||||
|
||||
/**
|
||||
* Main Application class that initializes and provides access to certain things like
|
||||
* logging and DB access.
|
||||
@ -104,6 +106,9 @@ public class GBApplication extends Application {
|
||||
private static final String PREFS_VERSION = "shared_preferences_version";
|
||||
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
|
||||
private static final int CURRENT_PREFS_VERSION = 7;
|
||||
|
||||
private static final int ERROR_IN_GADGETBRIDGE_NOTIFICATION = 42;
|
||||
|
||||
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
|
||||
private static Prefs prefs;
|
||||
private static GBPrefs gbPrefs;
|
||||
@ -208,7 +213,7 @@ public class GBApplication extends Application {
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationChannel channelHighPr = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID );
|
||||
NotificationChannel channelHighPr = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID);
|
||||
if (channelHighPr == null) {
|
||||
channelHighPr = new NotificationChannel(NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID,
|
||||
getString(R.string.notification_channel_high_priority_name),
|
||||
@ -219,7 +224,23 @@ public class GBApplication extends Application {
|
||||
bluetoothStateChangeReceiver = new BluetoothStateChangeReceiver();
|
||||
registerReceiver(bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||
}
|
||||
startService(new Intent(this, NotificationCollectorMonitorService.class));
|
||||
try {
|
||||
startService(new Intent(this, NotificationCollectorMonitorService.class));
|
||||
} catch (IllegalStateException e) {
|
||||
String message = e.toString();
|
||||
if (message == null) {
|
||||
message = getString(R.string._unknown_);
|
||||
}
|
||||
notificationManager.notify(ERROR_IN_GADGETBRIDGE_NOTIFICATION,
|
||||
new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID)
|
||||
.setSmallIcon(R.drawable.gadgetbridge_img)
|
||||
.setContentTitle(getString(R.string.error_background_service))
|
||||
.setContentText(getString(R.string.error_background_service_reason_truncated))
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(getString(R.string.error_background_service_reason) + "\"" + message + "\""))
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -880,6 +880,9 @@
|
||||
<string name="about_additional_contributions">Many thanks to all unlisted contributors for contributing code, support, ideas, motivation, bug reports, money… ✊</string>
|
||||
<string name="permission_granting_mandatory">All these permissions are required and instability might occur if not granted</string>
|
||||
<string name="error_version_check_extreme_caution">CAUTION: Error when checking version information! You should not continue! Saw version name \"%s\"</string>
|
||||
<string name="error_background_service">Failed to start background service</string>
|
||||
<string name="error_background_service_reason_truncated">Starting the background service failed because…</string>
|
||||
<string name="error_background_service_reason">Starting the background service failed because of an exception. Error: </string>
|
||||
<plurals name="widget_alarm_target_hours">
|
||||
<item quantity="one">%d hour</item>
|
||||
<item quantity="two">%d hours</item>
|
||||
|
Loading…
Reference in New Issue
Block a user