use of android.app.ActivityManager.RunningAppProcessInfo in project superCleanMaster by joyoyao.
the class AppUtil method getRunningAppProcesses.
/**
* 描述:获取运行的进程列表.
*
* @param context
* @return
*/
public static List<AppProcessInfo> getRunningAppProcesses(Context context) {
ActivityManager activityManager = null;
List<AppProcessInfo> list = null;
PackageManager packageManager = null;
try {
activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
packageManager = context.getApplicationContext().getPackageManager();
list = new ArrayList<AppProcessInfo>();
// 所有运行的进程
List<RunningAppProcessInfo> appProcessList = activityManager.getRunningAppProcesses();
ApplicationInfo appInfo = null;
AppProcessInfo abAppProcessInfo = null;
PackageInfo packageInfo = getPackageInfo(context);
if (mProcessList != null) {
mProcessList.clear();
}
mProcessList = getProcessRunningInfo();
for (RunningAppProcessInfo appProcessInfo : appProcessList) {
abAppProcessInfo = new AppProcessInfo(appProcessInfo.processName, appProcessInfo.pid, appProcessInfo.uid);
appInfo = getApplicationInfo(context, appProcessInfo.processName);
if (appInfo != null) {
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
abAppProcessInfo.isSystem = true;
} else {
abAppProcessInfo.isSystem = false;
}
Drawable icon = appInfo.loadIcon(packageManager);
String appName = appInfo.loadLabel(packageManager).toString();
abAppProcessInfo.icon = icon;
abAppProcessInfo.appName = appName;
} else {
// :服务的命名
if (appProcessInfo.processName.indexOf(":") != -1) {
appInfo = getApplicationInfo(context, appProcessInfo.processName.split(":")[0]);
Drawable icon = appInfo.loadIcon(packageManager);
abAppProcessInfo.icon = icon;
}
abAppProcessInfo.isSystem = true;
abAppProcessInfo.appName = appProcessInfo.processName;
}
/*
* AbPsRow psRow = getPsRow(appProcessInfo.processName);
* if(psRow!=null){ abAppProcessInfo.memory = psRow.mem; }
*/
ProcessInfo processInfo = getMemInfo(appProcessInfo.processName);
abAppProcessInfo.memory = processInfo.memory;
abAppProcessInfo.cpu = processInfo.cpu;
abAppProcessInfo.status = processInfo.status;
abAppProcessInfo.threadsCount = processInfo.threadsCount;
list.add(abAppProcessInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project ZI by yixia.
the class ProcessHelper method isProcessRunning.
public static boolean isProcessRunning(Context ctx, String name) {
ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo app : apps) {
if (app.processName.equals(name)) {
return true;
}
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project Lazy by l123456789jy.
the class AppUtils method isNamedProcess.
/**
* whether this process is named with processName
*
* @param context 上下文
* @param processName 进程名
* @return 是否含有当前的进程
*/
public static boolean isNamedProcess(Context context, String processName) {
if (context == null || TextUtils.isEmpty(processName)) {
return false;
}
int pid = android.os.Process.myPid();
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
if (processInfoList == null) {
return true;
}
for (RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == pid && processName.equalsIgnoreCase(processInfo.processName)) {
return true;
}
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project react-native-push-notification by zo0r.
the class RNPushNotificationHelper method isApplicationInForeground.
public boolean isApplicationInForeground() {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
if (processInfos != null) {
for (RunningAppProcessInfo processInfo : processInfos) {
if (processInfo.processName.equals(context.getPackageName()) && processInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && processInfo.pkgList.length > 0) {
return true;
}
}
}
return false;
}
use of android.app.ActivityManager.RunningAppProcessInfo in project YhLibraryForAndroid by android-coco.
the class SystemUtils method gc.
/**
* 清理后台进程与服务
*
* @param cxt 应用上下文对象context
* @return 被清理的数量
*/
public static int gc(Context cxt) {
long i = getDeviceUsableMemory(cxt);
// 清理掉的进程数
int count = 0;
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
// 获取正在运行的service列表
List<RunningServiceInfo> serviceList = am.getRunningServices(100);
if (serviceList != null) {
for (RunningServiceInfo service : serviceList) {
if (service.pid == android.os.Process.myPid()) {
continue;
}
try {
android.os.Process.killProcess(service.pid);
count++;
} catch (Exception e) {
e.getStackTrace();
continue;
}
}
}
// 获取正在运行的进程列表
List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
if (processList != null) {
for (RunningAppProcessInfo process : processList) {
// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
// pkgList 得到该进程下运行的包名
String[] pkgList = process.pkgList;
for (String pkgName : pkgList) {
LogUtils.e("======正在杀死包名:" + pkgName);
try {
am.killBackgroundProcesses(pkgName);
count++;
} catch (Exception e) {
// 防止意外发生
e.getStackTrace();
continue;
}
}
}
}
}
LogUtils.e("清理了" + (getDeviceUsableMemory(cxt) - i) + "M内存");
return count;
}
Aggregations