如何启动来自库的另一个应用程序的活动?

问题描述 投票:0回答:1

所以我有2个应用程序。假设我在应用程序A中,我知道有应用程序B并且它正在使用库C.库C有一个我想从应用程序A启动的活动。我该怎么做?

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

android android-intent android-library
1个回答
1
投票

在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);
}
© www.soinside.com 2019 - 2024. All rights reserved.