-
大小: 25KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-05-23
- 语言: Java
- 标签: Android5.0 应用
资源简介
Android 5.0以上获取系统运行进程信息, 5.0系统getRunningAppProcesses 已经失效了。http://www.cnblogs.com/luoyangcn/p/4936830.html
代码片段和文件信息
/*
* Copyright (C) 2015. Jared Rummler
*
* Licensed under the Apache License Version 2.0 (the “License“);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing software
* distributed under the License is distributed on an “AS IS“ BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.jaredrummler.android.processes;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import com.jaredrummler.android.processes.models.AndroidAppProcess;
import com.jaredrummler.android.processes.models.AndroidProcess;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* Helper class to get a list of processes on Android.
*
* Note: Every method in this class should not be executed on the main thread.
*/
public class ProcessManager {
private ProcessManager() {
throw new Assertionerror(“no instances“);
}
/**
* @return a list of all processes running on the device.
*/
public static List getRunningProcesses() {
List processes = new ArrayList<>();
File[] files = new File(“/proc“).listFiles();
for (File file : files) {
if (file.isDirectory()) {
int pid;
try {
pid = Integer.parseInt(file.getName());
} catch (NumberFormatException e) {
continue;
}
try {
processes.add(new AndroidProcess(pid));
} catch (IOException e) {
// If you are running this from a third-party app then system apps will not be
// readable on Android 5.0+ if SELinux is enforcing. You will need root access or an
// elevated SELinux context to read all files under /proc.
// See: https://su.chainfire.eu/#selinux
}
}
}
return processes;
}
/**
* @return a list of all running app processes on the device.
*/
public static List getRunningAppProcesses() {
List processes = new ArrayList<>();
File[] files = new File(“/proc“).listFiles();
for (File file : files) {
if (file.isDirectory()) {
int pid;
try {
pid = Integer.parseInt(file.getName());
} catch (NumberFormatException e) {
continue;
}
try {
processes.add(new AndroidAppProcess(pid));
} catch (AndroidAppProcess.NotAndroidAppProcessException ignored) {
} catch (IOException e) {
// If you are running this from a third-party app then system apps will
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-11-04 18:00 com\
目录 0 2015-11-04 18:00 com\jaredrummler\
目录 0 2015-11-04 18:00 com\jaredrummler\android\
目录 0 2015-11-04 18:00 com\jaredrummler\android\processes\
目录 0 2015-11-04 18:00 com\jaredrummler\android\processes\models\
文件 3915 2015-11-04 12:47 com\jaredrummler\android\processes\models\AndroidAppProcess.java
文件 26238 2015-11-04 12:47 com\jaredrummler\android\processes\models\AndroidProcess.java
文件 2988 2015-11-04 12:47 com\jaredrummler\android\processes\models\Cgroup.java
文件 1943 2015-11-04 12:47 com\jaredrummler\android\processes\models\ControlGroup.java
文件 2332 2015-11-04 12:47 com\jaredrummler\android\processes\models\ProcFile.java
文件 22590 2015-11-04 12:47 com\jaredrummler\android\processes\models\Stat.java
文件 2661 2015-11-04 12:47 com\jaredrummler\android\processes\models\Statm.java
文件 6632 2015-11-04 12:47 com\jaredrummler\android\processes\models\Status.java
文件 7385 2015-11-04 16:05 com\jaredrummler\android\processes\ProcessManager.java
相关资源
- 钉钉企业应用Demo(Java)
- 使用pyqtdeploy 发布你的 pyqt5 应用程序
- 直方图应用相似图片识别Java
- 图书管理系统毕业设计+源码 - Java源码
- java 正则表达式应用jar包 regex-smart.j
- 用Animation动画实现Android应用的欢迎界
- Android应用源码精致备忘录+课程表项目
- 简单的记事本android应用源代码
- android仿新浪微博应用
- android4.0跨应用共享数据通过sharepref
- android应用注册界面
- Android安卓逆向教程
- Android应用源码给安卓app加密码的项目
- Android 仿新浪微博客户端APP源码.rar
- Java手机通讯录应用源码.rar
- JavaEE轻量级框架应用与开发——S2SH答
- Android应用源码蓝牙串口搜索配对连接
- Jpcap资料与应用
- Android检测用户心率应用源码
- QTS青训-java8 高级应用与开发 实验答案
- 《Android Studio应用程序设计》第2版例
- android简单传感器应用代码光线传感器
- Android应用源码之蓝虫火车票余票查询
- Android应用源码之手机实时视频监控项
- Android应用案例-《垃圾短信助手案例
- SQlite Android SQLite的应用 简易的学生成
- 如何在webview中访问APP包中本地资源,
- 计算机组成原理(BOOTH算法)java源代
- Android中获取正在运行的应用程序Act
- android平台联系人管理应用源码+项目项
评论
共有 条评论