1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-05 17:57:03 +01:00

Extract a method for easier reuse if necessary

This commit is contained in:
cpfeiffer 2015-08-06 22:24:44 +02:00
parent 64298fc9af
commit f4cb798977

View File

@ -57,17 +57,9 @@ public class NotificationListener extends NotificationListenerService {
* else the service would get started every time we get a notification. * else the service would get started every time we get a notification.
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with * unfortunately we cannot enable/disable NotificationListener at runtime like we do with
* broadcast receivers because it seems to invalidate the permissions that are * broadcast receivers because it seems to invalidate the permissions that are
* neccessery for NotificationListenerService * necessary for NotificationListenerService
*/ */
boolean isServiceRunning = false; if (!isServiceRunning()) {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (DeviceCommunicationService.class.getName().equals(service.service.getClassName())) {
isServiceRunning = true;
}
}
if (!isServiceRunning) {
return; return;
} }
@ -128,6 +120,16 @@ public class NotificationListener extends NotificationListenerService {
} }
private boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (DeviceCommunicationService.class.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
@Override @Override
public void onNotificationRemoved(StatusBarNotification sbn) { public void onNotificationRemoved(StatusBarNotification sbn) {