version:1.0
update:2021-10-13 18:52:13 fix:去除okgo,rxAndroid1,优化依赖 add:切换到奥乐云平台
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.aoleyun.sn.utils;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
|
||||
public class ServiceAliveUtils {
|
||||
public static boolean isServiceAlive(Context mContext) {
|
||||
boolean isServiceRunning = false;
|
||||
ActivityManager manager =
|
||||
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (manager == null) {
|
||||
return false;
|
||||
}
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (mContext.getClass().getName().equals(service.service.getClassName())) {
|
||||
isServiceRunning = true;
|
||||
}
|
||||
}
|
||||
Logutils.i("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning);
|
||||
return isServiceRunning;
|
||||
}
|
||||
|
||||
public static boolean isServiceAlive(Context mContext, String serviceName) {
|
||||
boolean isServiceRunning = false;
|
||||
ActivityManager manager =
|
||||
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (manager == null) {
|
||||
return false;
|
||||
}
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (serviceName.equals(service.service.getClassName())) {
|
||||
isServiceRunning = true;
|
||||
}
|
||||
}
|
||||
Logutils.i("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning);
|
||||
return isServiceRunning;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user