2

Just a little problem:

For example I have the activity TestActivity in my Application com.example.testapp
but the activity doesn't have the flag android.intent.category.LAUNCHER

now my question is how can i check if a given activity subpackage.SomeActivity
exists in a Package com.test.somepackage

it would be the same as typing in a console:

adb shell am start -n com.test.somepackage/subpackage.SomeActivity

and if it exists, how can i launch it from another app?

××××× to clarify my question ×××××

i am searching for functions in android like
Intent startthis = new Intent (packagename, activityname);

and if its possible something like
ActivityInfo[] ai = fetchAllActivitysFromPackage(packagename);

is there any function in android that does likely the same?

bricklore
  • 3,985
  • 1
  • 28
  • 60
  • 1
    Why do you need this? – hichris123 Oct 27 '13 at 20:11
  • [This question](http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent) solves your problem? – Alfredo Cavalcanti Oct 27 '13 at 20:27
  • @hichris123 i need it because i want to have a list with all installed apps and all directly callable activitys (there is no better reason) – bricklore Oct 27 '13 at 21:30
  • Then you could use a PackageManager http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstalledApplications(int). – hichris123 Oct 27 '13 at 21:32
  • i got so far already. my last problem is how can i choose an activity to start if i know the package name? something like `new Intent (packagename, activityname)` and if its possible something like `ActivityInfo[] ai = fetchAllActivitysFromPackage(packagename)` those functions i search for or anything that does the same – bricklore Oct 27 '13 at 21:36

1 Answers1

3

You can get all activities for packages the following way:

List<PackageInfo> installedPackages = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
Iterator packageIterator = installedPackages.iterator();
PackageInfo packageInfo = null;
while(packageIterator.hasNext()){
    packageInfo = (PackageInfo) packageIterator.next();
    if(packageInfo.activities != null){
        for(ActivityInfo activity : packageInfo.activities){
            Log.d("ACTIVITY", activity.name);
        }
    }
}

However, you can only start an external activity if that app has defined an intent-filter for it, and if you now the exact ACTION of the intent filter.

Update: To get all activities for one package name, use:

PackageInfo packageInfo = getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
Jeffrey Klardie
  • 2,969
  • 1
  • 15
  • 23
  • 2
    thanks that works like a charm for my first question, thanks! i found out myself how to start one of the activitys later: `Intent intent = new Intent();` `intent.setClassName("com.test.packagename", ".Activity");` `intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)` `context.startActivity(intent);` – bricklore Oct 28 '13 at 07:44