Skip to content

Repository files navigation

AndroidProcesses

A small Android library to get the current running processes

APILicenseMaven Central


PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED

Google has significantly restricted access to /proc in Android Nougat. This library will not work on Android 7.0. Please star this issue.

More details can be found at:

What is this library for?

This small library can get a list of running apps and does not require any permissions.

Why would I need this?

Android 5.0+ killed getRunningTasks(int) and getRunningAppProcesses(). Both of these methods are now deprecated and only return the caller’s application process.

Android 5.0 introduced UsageStatsManager which provides access to device usage history and statistics. This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.

Usage

Get a list of running apps:

// Get a list of running appsList<AndroidAppProcess> processes = AndroidProcesses.getRunningAppProcesses();
for (AndroidAppProcessprocess : processes) {
// Get some information about the processStringprocessName = process.name;
Statstat = process.stat();
intpid = stat.getPid();
intparentProcessId = stat.ppid();
longstartTime = stat.stime();
intpolicy = stat.policy();
charstate = stat.state();
Statmstatm = process.statm();
longtotalSizeOfProcess = statm.getSize();
longresidentSetSize = statm.getResidentSetSize();
PackageInfopackageInfo = process.getPackageInfo(context, 0);
StringappName = packageInfo.applicationInfo.loadLabel(pm).toString();
}

Limitations

  • System apps will not be included on some Android versions because they have a higher SELinux context.
  • This is not a full replacement of getRunningAppProcesses(). The library does not provide a processes' pkgList, lru, or importance.
  • This is currently not working on the N developer preview.

Download

Download the latest AAR or grab via Gradle:

compile 'com.jaredrummler:android-processes:1.1.1'

or Maven:

<dependency>
<groupId>com.jaredrummler</groupId>
<artifactId>android-processes</artifactId>
<version>1.1.1</version>
<type>aar</type>
</dependency>

License

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.

About

DEPRECATED

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages