This commit is contained in:
Dennis Guse
2019-10-30 19:52:24 +01:00
parent 501e899b27
commit 419279fe5e
3 changed files with 46 additions and 32 deletions
@@ -0,0 +1,40 @@
package de.dennisguse.opentracks.util;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import java.util.List;
import de.dennisguse.opentracks.services.TrackRecordingService;
public class ServiceUtils {
private ServiceUtils() {
}
/**
* Returns true if the recording service is running.
*
* @param context the current context
*/
@Deprecated
public static boolean isTrackRecordingServiceRunning(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return false;
}
//TODO This approach is deprecated as of API level 26 and should be replaced.
List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
for (ActivityManager.RunningServiceInfo serviceInfo : services) {
ComponentName componentName = serviceInfo.service;
String serviceName = componentName.getClassName();
if (TrackRecordingService.class.getName().equals(serviceName)) {
return true;
}
}
return false;
}
}