[英]How to launch an activity of another app that's from a library?
So I have 2 apps. 所以我有2个应用。 Let's say I'm in app A, and I know that there is app B and that it is using library C. Library C has an activity that i want to launch from app A. How can I do that?
假设我在应用程序A中,并且我知道有应用程序B,并且它正在使用库C。库C的活动是我想从应用程序A启动的。我该怎么做?
EDIT: Actually, both A and B apps are using the same library. 编辑:实际上,A和B应用程序都使用相同的库。 But my goal is to launch an activity of the another app.
但我的目标是启动另一个应用程序的活动。
Try this code in Kotlin : 在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)
}
or in Java: 或使用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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.