use of android.app.ActivityManager.RunningServiceInfo in project LshUtils by SenhLinsh.
the class AppUtils method isServiceRunning.
/**
* 检查服务是否正在运行
*/
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
//获取Activity管理器
ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
//获取运行中服务
List<RunningServiceInfo> services = manager.getRunningServices(1000);
String serviceName = service.getName();
for (RunningServiceInfo info : services) {
//获取每一条运行中的服务的类名并判断
String name = info.service.getClassName();
if (TextUtils.equals(serviceName, name)) {
return true;
}
}
return false;
}
use of android.app.ActivityManager.RunningServiceInfo in project android_packages_apps_Torch by CyanogenMod.
the class TorchSwitch method torchServiceRunning.
private boolean torchServiceRunning(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> svcList = am.getRunningServices(100);
for (RunningServiceInfo serviceInfo : svcList) {
ComponentName serviceName = serviceInfo.service;
if (serviceName.getClassName().endsWith(".TorchService") || serviceName.getClassName().endsWith(".RootTorchService"))
return true;
}
return false;
}
use of android.app.ActivityManager.RunningServiceInfo in project AndroidUtilCode by Blankj.
the class ServiceUtils method getAllRunningService.
/**
* 获取所有运行的服务
*
* @param context 上下文
* @return 服务名集合
*/
public static Set getAllRunningService(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF);
Set<String> names = new HashSet<>();
if (infos == null || infos.size() == 0)
return null;
for (RunningServiceInfo info : infos) {
names.add(info.service.getClassName());
}
return names;
}
use of android.app.ActivityManager.RunningServiceInfo in project AndroidUtilCode by Blankj.
the class ServiceUtils method isServiceRunning.
/**
* 判断服务是否运行
*
* @param context 上下文
* @param className 完整包名的服务类名
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isServiceRunning(Context context, String className) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF);
if (infos == null || infos.size() == 0)
return false;
for (RunningServiceInfo info : infos) {
if (className.equals(info.service.getClassName()))
return true;
}
return false;
}
use of android.app.ActivityManager.RunningServiceInfo in project AprilBeacon-Android-SDK by AprilBrother.
the class ServiceStatusUtils method isServiceRunning.
public static boolean isServiceRunning(Context context, String serviename) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> infos = am.getRunningServices(100);
for (RunningServiceInfo info : infos) {
String classname = info.service.getClassName();
if (serviename.equals(classname)) {
return true;
}
}
return false;
}
Aggregations