How to launch an Activity from another Application in Android

后端 未结 12 1628
春和景丽
春和景丽 2020-11-21 06:02

I want to launch an installed package from my Android application. I assume that it is possible using intents, but I didn\'t find a way of doing it. Is there a link, where t

12条回答
  •  我寻月下人不归
    2020-11-21 06:29

    It is possible to start an app's activity by using Intent.setClassName according to the docs.

    An example:

    val activityName = "com.google.android.apps.muzei.MuzeiActivity" // target activity name
    val packageName = "net.nurik.roman.muzei" // target package's name
    val intent = Intent().setClassName(packageName, activityName)
    startActivity(intent)
    

    To open it outside the current app, add this flag before starting the intent.

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    

    A related answer here

提交回复
热议问题