-
大小: 25KB文件類型: .zip金幣: 2下載: 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
評論
共有 條評論