Extract a method for easier reuse if necessary
This commit is contained in:
parent
64298fc9af
commit
f4cb798977
|
@ -57,17 +57,9 @@ public class NotificationListener extends NotificationListenerService {
|
|||
* else the service would get started every time we get a notification.
|
||||
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with
|
||||
* broadcast receivers because it seems to invalidate the permissions that are
|
||||
* neccessery for NotificationListenerService
|
||||
* necessary for NotificationListenerService
|
||||
*/
|
||||
boolean isServiceRunning = false;
|
||||
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) {
|
||||
if (!isServiceRunning()) {
|
||||
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
|
||||
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue