Solution 1 :
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).
Problem :
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
. 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.
The Activity Launcher app is open source, so I tried reviewing the source code here. 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. 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}; have you declared this activity in your AndroidManifest.xml?
I have put both of the following in my Android Manifest and the same thing happens:
<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
Edit: David Wasser helped me solve the problem by giving me the code neccessary to solve the problem. 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. Problem Solved!
Comments
Comment posted by David Wasser
You need to know the exact package name and the exact class name of the
Comment posted by Richard Browning
Thanks for your comment , but I do know the package name of the app I want to launch. It is com.pas.webcam.pro. The activity or class I want to launch is RollingActivity or simply Rolling. This activity can be launched by a third party app, because the Activity Launcher app in the Play Store can launch this specific, as well as any, activity. So are you saying I need to add something to the manifest of my app? Because I am pretty sure my code is fine. Thanks.
Comment posted by David Wasser
You don’t need anything in your manifest. You need to know the exact package name of the other app (this is in the other app’s manifest) and you need to know the exact fully qualified class name of the
Comment posted by David Wasser
If you don’t have the manifest (or APK) of the other app, there are ways to get this information using
Comment posted by Richard Browning
I am absolutely 100% positive the CORRECT package name is com.pas.webcam.pro. The name of the activity is DEFINITELY Rolling. com.pas.webcam.pro.Rolling is DEFINITELY CORRECT. I do not need to query the Package Manager. I already have the package name and activity to launch. If you are sure I do not have to add anything to the Manifest, which I think is correct, what am i doing wrong? Is my code bad? How do I launch this activity of this package? Thanks.
Comment posted by Richard Browning
Wow! I have been searching for weeks for a solution. I have probably tried 10 different types of code. Yet this short easy line of code works. Thank you, thank you so much. Yes, the package name is com.pas.webcam.pro. I knew that. You are correct. Again, THANK YOU. IT WORKS. Woohoo.
Comment posted by David Wasser
Glad this solved your problem. You can accept my answer by clicking the green checkmark next to the answer. This will remove the question from the list of open questions and perhaps help others with a similar problem.