【发布时间】:2020-11-14 21:29:23
【问题描述】:
如果有人能帮我解决以下问题,我将不胜感激。
我正在尝试在 android studio 中构建 APK,但遇到了错误。
错误:
e: D:\WT\ZY\3.0\app\src\main\java\com\app\zy\cameraX\cameraxbasic\utils\Utils.kt: (117, 34): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ComponentName?
这段代码是:
fun isAppIsInBackground(context: Context): Boolean {
var isInBackground = true
val am = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
val runningProcesses = am.runningAppProcesses
for (processInfo in runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (activeProcess in processInfo.pkgList) {
if (activeProcess == context.packageName) {
isInBackground = false
}
}
}
}
} else {
val taskInfo = am.getRunningTasks(1)
val componentInfo = taskInfo[0].topActivity
if (componentInfo.packageName == context.packageName) {
isInBackground = false
}
}
错误行是
if (componentInfo.packageName == context.packageName) {
如果有人可以帮助我,不胜感激。
谢谢
【问题讨论】:
标签: android