title: Resetting Package Manager Cache
body: <p>I'm working on an Android app that allows a user to download and view a series of files, mostly PDF. When a user clicks on a file link to a PDF it is using the PackageManager to figure out if the user has an app installed that can display the file, and if so lets them launch it. If they do not they are allowed to download and save the file. </p>
  
  <p>I'm running into an issue for every new device or emulator we try this on. If a device doesn't have an existing PDF reader they get the "No application found" dialog. If I go to google play and install one then try and download the file again the app still doesn't know there's a PDF reader. </p>
  
  <p>I've tried restarting the device, clearing the the cache and data for my app. I can't figure out how to get Package Manager to update and realize there's an app installed that can handle it. </p>
  
  <p>Eventually it starts to work, but it can take a bit of time. </p>
  
  <p>Is there a way to force that to reset? I'm guessing package manager has a cache it's relying on. </p>
  
  <p>Here's my code for checking if there's an app installed that can handle the request. </p>
  
  <pre><code>    String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
      if (extension.equalsIgnoreCase("") || mimetype == null) {
          intent.setDataAndType(Uri.parse(resource.getUrl()), "text/*");
      } else {
          intent.setDataAndType(Uri.parse(resource.getUrl()), mimetype);
      }
  
      PackageManager packageManager = getActivity().getPackageManager();
      if (packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() &gt; 0) {
          startActivity(Intent.createChooser(intent, "Choose an Application:"));
          return;
      } else {
        // Show Error Dialog
      }
  </code></pre>