2

I'm trying to implement an application with similar functionality to MinimalisticText's ability to launch specific activities upon clicking a widget. I am making an app where I can select any application on the device, and then choose any activity from amongst those and launch it with a button press. However, I've hit the road block of getting an ActivityNotFoundException for not having said activity declared in my manifest.

All of my research has indicated that this is impossible; yet, applications like Minimalistic Text are somehow able to implement the functionality. What am I missing from my application to be able to launch the intents:

Here's the relevant code snippet for how I launch the activity:

     private Intent getLaunchIntent(ActivityInfo ainfo) {
        Intent launch = new Intent(ctx, ainfo.getClass());
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        if(DBG) { Log.i(TAG, "Got launch intent:" + launch.toString()); }

        return launch;
     }

EDIT: SOLVED! For anyone looking on how to do what I'm doing, look here:

Open another application from your own (intent)

Community
  • 1
  • 1
alextoombs
  • 33
  • 1
  • 7
  • I assume ctx is your context? if so you're trying to get the package information from your context as opposed to the package information of the Activity in question. Also ainfo.getClass() will return ActivityInfo.class – JRaymond Jul 16 '12 at 15:29
  • Okay, so both of those are an issue. I'm going to try to use the PackageInfo to get that package's own context and that activities' own class to construct the intent. – alextoombs Jul 16 '12 at 17:31

1 Answers1

0

Specifically from a manifest perspective its important to note that just because you have the Activity does NOT necessarily mean you can actually enter that particular activity. These specifics are defined by the Intent Filter of MAIN and Launcher Intent, which some activties will or will not have.

One thing to note is that if an activity does not have a MAIN, you cannot go to that activity directly via an intent outside of that package. Being denied access to this activity is working as intended as it is a security measure to prevent going to a particular screen outside of the designed scheme.

For details refer to: http://developer.android.com/reference/android/content/Intent

Also as a HINT you can use utilize the PackageManager to solve your problem of launching applications directly from another application (within the bounds mentioned above)

JoxTraex
  • 13,105
  • 5
  • 30
  • 45
  • Hmm, okay. Wasn't aware that was working as intended. As far as the API for getLaunchIntentForPackage(), I tried using that, but I'm more trying to open up separate activities rather than the MAIN activity of the package. It might not be possible, but thank you for your response. – alextoombs Jul 16 '12 at 17:31