微码:安卓中根据进程号获取进程名
本文发布于 2023年11月15日,阅读 53 次,点赞
2 次,归类于
微码
在安卓中根据进程号获取进程名:
private fun getProcessName(pid: Int): String? {
var reader: BufferedReader? = null
try {
reader = BufferedReader(FileReader("/proc/$pid/cmdline"))
var processName = reader.readLine()
if (!TextUtils.isEmpty(processName)) {
processName = processName.trim { it <= ' ' }
}
return processName
} catch (throwable: Throwable) {
throwable.printStackTrace()
} finally {
try {
reader?.close()
} catch (exception: IOException) {
exception.printStackTrace()
}
}
return null
}