title: IPackageStatsObserver cannot be resolved to a type (Android)
body: <p>I want to calculate the sum of all the cache memory utilizing the device. For this I am getting a compiled time error:</p>
  
  <pre><code>IPackageStatsObserver cannot be resolved to a type
  </code></pre>
  
  <p>I have mentioned this error 2 times in the code:</p>
  
  <pre><code>public long totalCacheSize(){
      totalSize=0;
  
      PackageManager packageManager = getApplicationContext().getPackageManager();
  
       /* List&lt;PackageInfo&gt; packs = packageManager
        .getInstalledPackages(PackageManager.GET_ACTIVITIES);*/
       // PackageManager.GET_META_DATA
  
      List&lt;PackageInfo&gt; packs = packageManager
              .getInstalledPackages(PackageManager.GET_META_DATA);
  
      for (int i = 0; i &lt; packs.size(); i++) {
  
          PackageInfo p = packs.get(i);
  
          Method getPackageSizeInfo;
          try {
              getPackageSizeInfo = packageManager.getClass()
                      .getMethod("getPackageSizeInfo",
                          String.class, Class.forName("android.content.pm.IPackageStatsObserver"));
  
              getPackageSizeInfo.invoke(packageManager, p.packageName,
                      new IPackageStatsObserver.Stub() { //error
  
                          public void onGetStatsCompleted(
                                  PackageStats pStats, boolean succeeded)
                                  throws RemoteException {
  
                              totalSize = totalSize + pStats.cacheSize;
                              Log.d("size", totalSize+"");
                              Toast.makeText(getApplicationContext(), "size"+totalSize, Toast.LENGTH_SHORT).show();
                          }
                      }
              );
  
          } catch (Exception e) {
              try {
                  getPackageSizeInfo = packageManager.getClass()
                          .getMethod("getPackageSizeInfo",
                              String.class, Class.forName("android.content.pm.IPackageStatsObserver"));
  
                  getPackageSizeInfo.invoke(packageManager, p.packageName,
                          new IPackageStatsObserver.Stub() { //error
  
                              public void onGetStatsCompleted(
                                      PackageStats pStats, boolean succeeded)
                                      throws RemoteException {
  
                                  totalSize = totalSize + pStats.cacheSize;
                                  Log.d("size", totalSize+"");
                                  Toast.makeText(getApplicationContext(), "size"+totalSize, Toast.LENGTH_SHORT).show();
                              }
                          }
                  );
              } catch (Exception ee) {
                  Log.d("eeeeeeeeeee", "error");
                  ee.printStackTrace();
              } 
          } 
      }
  
      Log.d("return size", totalSize+"");
      Toast.makeText(getApplicationContext(), "return size"+totalSize, Toast.LENGTH_SHORT).show();
      return totalSize;
  }
  </code></pre>
  
  <p><code>IPackageStatsObserver</code> is not available in android SDK. Perhaps loading the Stub class using <code>Class.forName()</code>, finding the default constructor and invoke it to get a new instance of a <code>Stub</code>. But what should I code it, I do not know anything about it!?</p>
  
  <p>Help !!</p>