title: getPackageManager and MockPackageManager
body: <p>I wanted to get a list of installed apps on a device <strong>by</strong> using <code>getInstalledApplications()</code> method from <code>MockPackageManager</code> class (Yes it is deprecated). I used the following code (in my activity):</p>
  <pre><code>MockPackageManager mpm = new MockPackageManager();
  List&lt;ApplicationInfo&gt; appInfoList = mpm.getInstalledApplications(0);
  </code></pre>
  <p>But it gave me this error:</p>
  <pre><code>java.lang.NoClassDefFoundError: Failed resolution of: Landroid/test/mock/MockPackageManager;
  </code></pre>
  <p>then found this way (which worked):</p>
  <pre><code> List&lt;ApplicationInfo&gt; appInfoList = getPackageManager().getInstalledApplications(0);
  </code></pre>
  <p>I looked at Android docs but only found these:</p>
  <blockquote>
  <p>Class for retrieving various kinds of information related to the application packages that are currently installed on the device. You can find this class through getPackageManager(). [PackageManager docs]</p>
  <p>Return PackageManager instance to find global package information.[Context docs about getPackageManager()]</p>
  </blockquote>
  <p>I really didn't understand <strong>why</strong> the first way is wrong and <strong>why</strong> I should first use <code>getPackageManager()</code> (<strong>what</strong> does it do?).</p>
  <p>Tnx in advance.</p>
  <p>P.S: Sorry if it is a simple(stupid!) question :)</p>