2010-04-18 7 views
3

Fondamentalement, je veux obtenir une liste de toutes les applications installées et en choisir une à exécuter à partir d'une activité.Comment démarrer une autre application (téléchargée ou préinstallée) à partir d'une activité?

J'ai essayé ACTION_PICK avec Intents mais cela semble ignorer les applications qui ont été téléchargées et qui contiennent beaucoup d'ordures.

Merci

+0

Pas exactement un doublon, mais l'information dont vous avez besoin est [ici] (http://stackoverflow.com/questions/2575962/app-install-history-on-android). – Macarse

Répondre

8
// to get the list of apps you can launch 
Intent intent = new Intent(ACTION_MAIN); 
intent.addCategory(CATEGORY_LAUNCHER); 
List<ResolveInfo> infos = getPackageManager().queryIntentActivities(intent, 0); 

// resolveInfo.activityInfo.packageName = packageName 
// resolveInfo.activityInfo.name = className 
// reusing that intent 
intent.setClassName(packageName, className); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
startActivity(intent) 

Espoir qui est assez pour vous aider à comprendre.

+0

merci je vais l'essayer plus tard – 2Real

+0

J'ai essayé ceci mais il ne montre pas toutes les applications installées, par exemple, celles qui sont téléchargées. – 2Real

0
final File favFile = new File(Environment.getRootDirectory(), DEFAULT_FAVORITES_PATH); 
      try { 
       favReader = new FileReader(favFile); 
      } catch (FileNotFoundException e) { 
       Log.e(LOG_TAG, "Couldn't find or open favorites file " + favFile); 
       return; 
      }//gives the path for downloaded apps in directory 







private void loadApplications(boolean isLaunching) { 
     if (isLaunching && mApplications != null) { 
      return; 
     } 

     PackageManager manager = getPackageManager(); 

     Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
     mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

     final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0); 
     Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager)); 

     if (apps != null) { 
      final int count = apps.size(); 

      if (mApplications == null) { 
       mApplications = new ArrayList<ApplicationInfo>(count); 
      } 
      mApplications.clear(); 

      for (int i = 0; i < count; i++) { 
        ApplicationInfo application = new ApplicationInfo(); 
       ResolveInfo info = apps.get(DEFAULT_KEYS_SEARCH_LOCAL); 

       application.title = info.loadLabel(manager); 
       application.setActivity(new ComponentName(
         info.activityInfo.applicationInfo.packageName, 
         info.activityInfo.name), 
         Intent.FLAG_ACTIVITY_NEW_TASK 
         | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
       application.icon = info.activityInfo.loadIcon(manager); 

       mApplications.add(application); 

     } 
    } 

Ceci vous aidera à charger toutes les applications téléchargées.

+0

@ 2Real jus vérifier le code ci-dessus j'ai utilisé celui-ci pour obtenir tous les paquets là-bas dans mon appareil espérons que celui-ci se révèle utile. –

Questions connexes