mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 23:55:08 +00:00
Fixed a crash in notificationsplugin
This commit is contained in:
@@ -221,13 +221,36 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
if (np.getBoolean("request")) {
|
if (np.getBoolean("request")) {
|
||||||
|
|
||||||
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
|
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
|
||||||
@Override
|
private void sendCurrentNotifications(NotificationReceiver service) {
|
||||||
public void onServiceStart(NotificationReceiver service) {
|
|
||||||
StatusBarNotification[] notifications = service.getActiveNotifications();
|
StatusBarNotification[] notifications = service.getActiveNotifications();
|
||||||
for (StatusBarNotification notification : notifications) {
|
for (StatusBarNotification notification : notifications) {
|
||||||
onNotificationPosted(notification, true);
|
onNotificationPosted(notification, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(final NotificationReceiver service) {
|
||||||
|
try {
|
||||||
|
//If service just started, this call will throw an exception because the answer is not ready yet
|
||||||
|
sendCurrentNotifications(service);
|
||||||
|
} catch(Exception e) {
|
||||||
|
Log.e("onPackageReceived","Error when answering 'request': Service failed to start. Retrying in 100ms...");
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
Log.e("onPackageReceived","Error when answering 'request': Service failed to start. Retrying...");
|
||||||
|
sendCurrentNotifications(service);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("onPackageReceived","Error when answering 'request': Service failed to start twice!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (np.has("cancel")) {
|
} else if (np.has("cancel")) {
|
||||||
|
Reference in New Issue
Block a user