Skip to content

Instantly share code, notes, and snippets.

@ShinichiroFunatsu
Last active March 25, 2022 09:09
Show Gist options
  • Save ShinichiroFunatsu/cf889a5c65af300acae0d6a79222ff42 to your computer and use it in GitHub Desktop.
Save ShinichiroFunatsu/cf889a5c65af300acae0d6a79222ff42 to your computer and use it in GitHub Desktop.
Android get current process
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