Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get list of apps
    text
    copied!<p>i got this code off the internet, i suppose to get a list of all the applications on the phone and judging by the comments on the webpage it works but i just cant seem to get it to work for me at all. it seems to be the getPacketManager() that is giving me the problem. can someone please look at the code and explain to me what i have to do to get it working please?</p> <p>this is my full class... i cant get it to even run, on the 3 locations where there is a "getPackageManager()" it is giving me an error on the left of the screen saying "The method getPackageManager() is undefined for the type getApps"</p> <pre><code>package cians.app; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.pm.PackageInfo; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class getApps{ class PInfo { private String appname = ""; private String pname = ""; private String versionName = ""; private int versionCode = 0; private Drawable icon; private void prettyPrint() { System.out.print(appname + "\\t" + pname + "\\t" + versionName + "\\t" +versionCode + "\\t"); } } private void listPackages() { ArrayList&lt;PInfo&gt; apps = getInstalledApps(false); /* false = no system packages */ final int max = apps.size(); for (int i=0; i&lt;max; i++) { apps.get(i).prettyPrint(); } } private ArrayList&lt;PInfo&gt; getInstalledApps(boolean getSysPackages) { ArrayList&lt;PInfo&gt; res = new ArrayList&lt;PInfo&gt;(); List&lt;PackageInfo&gt; packs = getPackageManager().getInstalledPackages(0); for(int i=0;i&lt;packs.size();i++) { PackageInfo p = packs.get(i); if ((!getSysPackages) &amp;&amp; (p.versionName == null)) { continue ; } PInfo newInfo = new PInfo(); 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; }} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload