• 大小: 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

评论

共有 条评论