Android 如何启动另一个';他是从图书馆来的?

Android 如何启动另一个';他是从图书馆来的?,android,android-intent,android-library,Android,Android Intent,Android Library,所以我有两个应用程序。假设我在应用程序A中,我知道有应用程序B,并且它正在使用库C。库C有一个我想从应用程序A启动的活动。我如何才能做到这一点 编辑:实际上,A和B应用程序都使用同一个库。但我的目标是启动另一个应用程序的活动。在Kotlin中尝试此代码: fun runDifferentActivity() { // Different app package val otherAppPackage = "comp.package.android.something.there"

所以我有两个应用程序。假设我在应用程序A中,我知道有应用程序B,并且它正在使用库C。库C有一个我想从应用程序A启动的活动。我如何才能做到这一点


编辑:实际上,A和B应用程序都使用同一个库。但我的目标是启动另一个应用程序的活动。

在Kotlin中尝试此代码:

fun runDifferentActivity() {
    // Different app package
    val otherAppPackage = "comp.package.android.something.there"
    // Activity name (from different App)
    val otherAppActivity = "SecretActivity"

    val action = "$otherAppPackage.$otherAppActivity"

    // Create Intent with action name
    val intent = Intent(action)

    // Start activity
    startActivity(intent)
}
或在Java中:

void runDifferentActivity() {
    // Different app package
    String otherAppPackage = "comp.package.android.something.there";

    // Activity name (from different App)
    String otherAppActivity = "SecretActivity";

    String action = String.format("%s.%s", otherAppPackage, otherAppActivity);

    // Create Intent with action name
    Intent intent = new Intent(action);

    // Start activity
    startActivity(intent);
}