mirror of
https://github.com/KitsunePie/AppErrorsTracking.git
synced 2025-09-04 02:05:16 +08:00
Modify change Context.openApp function can open multi-user's Activity
This commit is contained in:
@@ -338,13 +338,18 @@ fun Context.isAppCanOpened(packageName: String = this.packageName) =
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动指定 APP
|
* 启动指定 APP
|
||||||
* @param packageName 包名
|
* @param packageName APP 包名 - 默认为当前 APP
|
||||||
|
* @param userId APP 用户 ID - 默认 0
|
||||||
*/
|
*/
|
||||||
fun Context.openApp(packageName: String = this.packageName) = runCatching {
|
fun Context.openApp(packageName: String = getPackageName(), userId: Int = 0) = runCatching {
|
||||||
startActivity(packageManager.getLaunchIntentForPackage(packageName)?.apply {
|
val startingActivityName = packageManager.runCatching {
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
@Suppress("DEPRECATION")
|
||||||
})
|
if (Build.VERSION.SDK_INT >= 33)
|
||||||
}.onFailure { toast(msg = "Cannot start '$packageName'") }
|
queryIntentActivities(getLaunchIntentForPackage(packageName)!!, PackageManager.ResolveInfoFlags.of(0)).first().activityInfo.name
|
||||||
|
else queryIntentActivities(getLaunchIntentForPackage(packageName)!!, 0).first().activityInfo.name
|
||||||
|
}.getOrNull() ?: ""
|
||||||
|
Runtime.getRuntime().exec("am start -n $packageName/$startingActivityName --user $userId")
|
||||||
|
}.onFailure { toast(msg = "Cannot start \"$packageName\"${if (userId > 0) " for user $userId" else ""}") }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否有 Root 权限
|
* 是否有 Root 权限
|
||||||
|
Reference in New Issue
Block a user