简体   繁体   English

如何启动另一个应用程序的特定(显式)活动

[英]How do I launch a specific (explicit) activity of another app

I want to launch a specific activity of another app from my app.我想从我的应用程序启动另一个应用程序的特定活动。 For example, on the onCreate of my app, I want to launch the activity named Rolling (not main) activity of com.pas.webcam.pro .例如,在我的应用程序的onCreate上,我想启动名为Rolling (非主)活动的活动com.pas.webcam.pro I have heard that you must have control of both apps to do this because you must add an intent filter to the manifest of the second app.我听说您必须控制两个应用程序才能执行此操作,因为您必须将意图过滤器添加到第二个应用程序的清单中。 This is not true though, because activity launcher apps in the Google Play Store can launch the Rolling Activity of IP Webcam Pro.但事实并非如此,因为 Google Play 商店中的活动启动器应用程序可以启动 IP Webcam Pro 的滚动活动。

The Activity Launcher app is open source, so I tried reviewing the source code here . Activity Launcher 应用程序是开源的,因此我尝试在此处查看源代码 It was too complicated though, so I could not figure out how this app magically launches this activity.不过它太复杂了,所以我无法弄清楚这个应用程序是如何神奇地启动这个活动的。 There are many other questions like this on Stack Overflow, and I have read every one. Stack Overflow 上还有很多类似的问题,每一个我都看过。 I have also tried lots of the code from the answers too, like this:我也从答案中尝试了很多代码,如下所示:

Intent intent = new Intent(); intent.setComponent(new ComponentName("com.pas.webcam", "com.pas.webcam.RollingActivity")); startActivity(intent);

I have also tried variants of this code from other posts.我还尝试了其他帖子中此代码的变体。 My app always crashes and I get variants (depending on the code I use) of the following error :我的应用程序总是崩溃,并且我得到以下错误的变体(取决于我使用的代码):

An error occurred发生错误

Invalid intent operation.无效的意图操作。 Unable to find explicit activity class {com.pas.webcam.pro/com.pas.webcam.pro.Rolling};无法找到显式活动 class {com.pas.webcam.pro/com.pas.webcam.pro.Rolling}; have you declared this activity in your AndroidManifest.xml?您是否在 AndroidManifest.xml 中声明了此活动?

I have put both of the following in my Android Manifest and the same thing happens:我在我的 Android 清单中放入了以下两个内容,并且发生了同样的事情:

<uses-permission android:name="android.permission.GET_INSTALLED_PACKAGES" />

<activity android:name="com.pas.webcam.pro.RollingActivity"

Thanks in advance for any answers, I really appreciate it, as I have been working on this problem for a while.提前感谢您的任何答案,我真的很感激,因为我一直在研究这个问题一段时间。

Edit: Here is the activity of the app I want to launch: https://i.stack.imgur.com/Fa7Xq.jpg编辑:这是我要启动的应用程序的活动: https://i.stack.imgur.com/Fa7Xq.jpg

Edit: David Wasser helped me solve the problem by giving me the code neccessary to solve the problem.编辑:David Wasser 通过给我解决问题所需的代码帮助我解决了问题。 It actually works, To anyone who wants to launch a specific activity of another app with code: please use this:它确实有效,对于想要使用代码启动另一个应用程序的特定活动的任何人:请使用:

Intent intent = new Intent(); intent.setClassName("com.pas.webcam.pro", "com.pas.webcam.Rolling"); startActivity(intent);

You may replace com.pas.webcam.pro and Rolling with the app and activity of your choice, but this method truly works.您可以用您选择的应用程序和活动替换 com.pas.webcam.pro 和 Rolling,但这种方法确实有效。 Problem Solved!问题解决了!

Try this:尝试这个:

Intent intent = new Intent();
intent.setClassName("com.pas.webcam.pro", "com.pas.webcam.Rolling");
startActivity(intent);

Since you refer to the app as "IP webcam pro", I'm assuming the package name is "com.pas.webcam.pro" (found by Internet research).由于您将该应用程序称为“IP webcam pro”,我假设 package 名称为“com.pas.webcam.pro”(通过互联网研究发现)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM