androidfully-qualified-naming

How to acquire fully qualified names of installed applications in Android


I try to create an application that can start other applications (f.e. Gmail or Facebook or any installed one).

I tried to use the following code:

PackageManager pm = MainActivity.this.getPackageManager();
try
{
  Intent it = pm.getLaunchIntentForPackage("FULLY QUALIFIED NAME");
  if (it != null)
    MainActivity.this.startActivity(it);
}
catch (ActivityNotFoundException e)
{ }

However, it requires the fully qualified name of the application.

How can I acquire it? Is there any built-in method to get them?


Solution

  • An application may have zero, one, or several activities that belong in a launcher. Hence, a launcher should not be asking "what are all the applications, and what is the launch Intent for each?" A launcher should, instead, be asking "what are all of the activities that I should show?"

    That is accomplished using PackageManager and queryIntentActivities(). This sample project implements a complete launcher. The key lines are:

    PackageManager pm=getPackageManager();
    Intent main=new Intent(Intent.ACTION_MAIN, null);
    
    main.addCategory(Intent.CATEGORY_LAUNCHER);
    
    List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);
    

    Then, you can use whatever mechanism you want to render that launchables collection. The sample project puts them in a ListView.