Last active
March 25, 2022 09:09
-
-
Save ShinichiroFunatsu/cf889a5c65af300acae0d6a79222ff42 to your computer and use it in GitHub Desktop.
Android get current process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Context.currentProcess(): ActivityManager.RunningAppProcessInfo? { | |
val manager = getSystemService<ActivityManager>()!! | |
val pid = android.os.Process.myPid() | |
return manager.runningAppProcesses.firstOrNull { it.pid == pid } | |
} | |
fun Context.isMainProcess(): Boolean { | |
val currentProcess = currentProcess() | |
return currentProcess?.processName == BuildConfig.APPLICATION_ID | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment