在 dependencies 中添加库的引用
implementation 'com.jaredrummler:android-processes:1.1.1'
复制代码
Kotlin代码
private fun getAppList(): ArrayList<ResourceUsageBean> {
val runningAppProcesses = AndroidProcesses.getRunningAppProcesses()
val pm = activity!!.packageManager
for (runningAppProcess in runningAppProcesses){
val appInfo = pm.getApplicationInfo(runningAppProcess.packageName, PackageManager.GET_META_DATA)
ResourceUsageBean(pm.getApplicationIcon(appInfo) , pm.getApplicationLabel(appInfo).toString(),0,null,1,1)
appList.add(resourceUsageBean)
}
return appList
}
复制代码