Update: Abstract startLauncherActivity

This commit is contained in:
machiav3lli
2022-05-13 11:19:05 +02:00
parent ad0dc626e1
commit 688ae0be1f
2 changed files with 13 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import android.app.ActivityManager
import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE
import android.content.ActivityNotFoundException
import android.content.ComponentName
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
@@ -254,4 +255,16 @@ fun PackageManager.getLaunchActivities(packageName: String): List<Pair<String, S
}
}
.toList()
fun Context.startLauncherActivity(packageName: String, name: String) {
try {
startActivity(
Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setComponent(ComponentName(packageName, name))
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
} catch (e: Exception) {
e.printStackTrace()
}
}