javaandroid-intentandroid-activitylaunch

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. 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.sstatic.net/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!😀


Solution

  • 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).