Hello guys, I had a post here is about creating a list of installed apps.

and here is the code from the post:

List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();

for(ApplicationInfo app : apps) {
//checks for flags; if flagged, check if updated system app
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
//Discard this one
//in this case, it should be a user-installed app
} else {

String label = (String)pm.getApplicationLabel(app);
Drawable icon = pm.getApplicationIcon(app);

I try to use the code, but there has some errors.

app cannot be resolved to a variable
pm cannot be resolved
apps cannot be resolved to a variable

I define the app as 
ApplicationInfo app; 
does it correct?

Also, what are the pm and apps?
How should I change it?

Thank you so much for your help!!