I'm trying to develop an application launcher application for android. I'm in the very beginning but I have a problem here: How do I get a list of all installed applications in android?
Asked
Active
Viewed 6,952 times
3 Answers
3
Use these methods in your activty to get a list of installed applications.
private ArrayList<PackageInfoStruct> getPackages() {
ArrayList<PackageInfoStruct> apps = getInstalledApps(false);
final int max = apps.size();
for (int i=0; i < max; i++) {
apps.get(i);
}
return apps;
}
private ArrayList<PackageInfoStruct> getInstalledApps(boolean getSysPackages) {
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
try{
app_labels = new String[packs.size()];
}catch(Exception e){
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
for(int i=0;i < packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PackageInfoStruct newInfo = new PackageInfoStruct();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
app_labels[i] = newInfo.appname;
}
return res;
}
-
-
-
1It is just an object which holds the details of the application like application name, package , version etc.. – Rakshi Oct 09 '13 at 08:43
1
I'd suggest you to atleast search stackoverflow before posting a question.
From a duplicate question : via @karan
Following is the code to get the list of activities/applications installed on Android :
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
0
An updated solution based on COD3BOY's post above. I added the declaration of the struct. I should note also, maybe due to the large time gap between posts, that ArrayLists are accessed via arrList.get(i)
instead of arrList[i]
.
First the imports...
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
Then the functions...
public class PackageInfoStruct {
String appname = "";
String pname = "";
String versionName = "";
int versionCode = 0;
Drawable icon;
String datadir = "";
}
private ArrayList<PackageInfoStruct> getInstalledApps(boolean getSysPackages) {
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
ArrayList<PackageInfoStruct> res = new ArrayList<PackageInfoStruct>();
for(int i=0;i < packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PackageInfoStruct newInfo = new PackageInfoStruct();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}

bad_coder
- 11,289
- 20
- 44
- 72

justinhpatterson
- 1
- 2
- 4