How to get all apps installed on android phone

后端 未结 2 1343
梦谈多话
梦谈多话 2020-12-05 16:54

This is the code that i have at the moment but i still can\'t get a list of all the apps on the phone. Does anyone see what i am doing wrong?

public class G         


        
相关标签:
2条回答
  • 2020-12-05 17:01

    This code logs name and package name of all the installed applications. You can easily check the log using LogCat (if you are using Eclipse).

    Package name - name of the app's package.

    Name - text label associated with the application. You can't use just appInfo.name as it will return null. Using appInfo.loadLabel(packageManager) you get the actual app's name like Speech Recorder instead of package name com.android.speechrecorder.

    final PackageManager packageManager = getPackageManager();
    List<ApplicationInfo> installedApplications = 
       packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for (ApplicationInfo appInfo : installedApplications)
    {
        Log.d("OUTPUT", "Package name : " + appInfo.packageName);
        Log.d("OUTPUT", "Name: " + appInfo.loadLabel(packageManager));
    } 
    
    0 讨论(0)
  • 2020-12-05 17:16

    This is the code I use to list applications:

    PackageManager pm = this.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    
    String activityName = rInfo.activityInfo.name;
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
    
    for (ResolveInfo rInfo : list) {
        pkg = rInfo.activityInfo.applicationInfo.packageName;
        if (pm.getLaunchIntentForPackage(pkg) == null) {
          continue;
        }
        String label = rInfo.activityInfo.applicationInfo.loadLabel(pm).toString();
        arrayList.add(new AppEntry(label, activityName, pkg, null));
    }
    

    If you later on want to run application only knowing pkg and activityName you can do:

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(pkg, activityname);
    ctx.startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题