1

Applications can have any number of launchable activities. I know how to get the list of these activities via PackageManager.

Is there a way to determine which activities can be launched via startActivity?

For example, the Documents To Go app has different activities that will start Word, Excel, Powerpoint, PDF, etc... I am able to launch all o these just fine.

However, it also contains some activities that I am not able to launch with startActivity... If I attempt to do this I get a SecurityException.

I want to be able to determine which activities I can safely launch and which I cannot so I only present the user with a list of activities that I can safely launch from within my application...

Is this possible?

Justin
  • 6,564
  • 6
  • 37
  • 34

2 Answers2

1

Create the intent with the parameters/data that you have and then use the package manager resolveActivity() method to check for the activity which will be process your request.

Then check the permissions using checkPermission() method of PackageManager.

HTH !

Karan
  • 12,724
  • 6
  • 40
  • 33
  • Unfortunately, the resolveActivity() method is only for implicit intents. Since I have the package and class names for the activities I am launching (I am getting them through PackageManager) this method will not work for what I want to do. I'm not having a problem FINDING the activity to launch. The problem is that when I attempt to launch it via startActivity() I get a SecurityException error... Any other suggestions are welcome. – Justin Jun 10 '10 at 23:59
  • For what it's worth, the exact error I am getting from the SecurityException is this: Permission Denial: starting Intent { flg=0x10600000 cmp=com.dataviz.docstogo/com.dataviz.dxtg.common.android.WelcomeScreenActivity } from ProcessRecord{43565cb0 14660:com.magouyaware.appswipe/10043} (pid=14660, uid=10043) requires null – Justin Jun 11 '10 at 00:10
  • However, I can successfully launch other activities provided by the Docs To Go application. So the question is, how can I determine which ones I can and cannot launch... (Note that using Docs To Go is just an example... This exact same problem ocurrs with many different apps) – Justin Jun 11 '10 at 00:28
0

This is probably old hat to you but you can use this method:

getPackageManager().getLaunchIntentForPackage(
                packageName);

Here is a way to get the package names of installed apps:

final PackageManager pm = getPackageManager();

        List<ApplicationInfo> packages = pm
                .getInstalledApplications(PackageManager.GET_META_DATA);

        for (ApplicationInfo packageInfo : packages) {

            Log.d(TAG, "Installed package :" + packageInfo.packageName);
            Log.d(TAG,
                    "Launch Activity :"
                            + pm.getLaunchIntentForPackage(packageInfo.packageName));

        }
Nelson Ramirez
  • 7,864
  • 7
  • 28
  • 34
  • Thanks Nelson, but that does not actually answer my question. The code you have finds an intent to launch the default activity for a given package. My requirement is different. I already have both the package name and class name for a given activity... In most cases I can launch it with an explicit intent. However, in some cases I get a permission denied error... All of my efforts to check if I have permission to launch the activity are ignored and I still get the SecurityException saying permission is denied. – Justin Mar 22 '11 at 13:35
  • Ah, I understand now. If you're able to catch the error that's probably as good as it gets. Sorry i couldn't help. – Nelson Ramirez Mar 31 '11 at 21:16