title: Android intent to open gallery doesn't work on KitKat (4.4)
body: <p>I am developing an app that needs to allow the user to select a Profile picture, and I want to give them an easy option to either take a picture, or choose an existing one from the Gallery.</p>
  
  <p>My searches took me to <a href="https://stackoverflow.com/questions/4455558/allow-user-to-select-camera-or-gallery-for-image">this Stackoverflow discussion</a>, so I modified the code in one of the answers for my purposes. Here is what I have:</p>
  
  <pre><code>public static Uri openImageIntent(Activity context) {
      Uri outputFileUri = null;
      File cache_dir = context.getExternalFilesDir("photos");
  
      cache_dir.mkdirs();
  
      File image_file = null;
      try {
          image_file = File.createTempFile("profile", ".jpg", cache_dir);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      if (image_file != null) {
          File sdImageMainDirectory = new File(cache_dir.getAbsolutePath(), image_file.getName());
          outputFileUri = Uri.fromFile(sdImageMainDirectory);
  
          // Camera.
          List&lt;Intent&gt; cameraIntents = new ArrayList&lt;Intent&gt;();
          Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
          PackageManager packageManager = context.getPackageManager();
          List&lt;ResolveInfo&gt; listCam = packageManager.queryIntentActivities(captureIntent, 0);
  
          for(ResolveInfo res : listCam) {
              final String packageName = res.activityInfo.packageName;
              final Intent intent = new Intent(captureIntent);
              intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
              intent.setPackage(packageName);
              intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
              cameraIntents.add(intent);
          }
  
          // Filesystem.
          final Intent galleryIntent = new Intent();
          galleryIntent.setType("image/*");
          galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
  
          // Chooser of filesystem options.
          final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
  
          // Add the camera options.
          chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));
  
          context.startActivityForResult(chooserIntent, Constants.RequestCodes.CHOOSE_PICTURE);
      }
  
      return outputFileUri;
   }
  </code></pre>
  
  <p>As you can see, it creates a chooser by combining the ACTION_IMAGE_CAPTURE and ACTION_GET_CONTENT intents, with the latter being filtered for "image/*". The goal here is to open up a custom choose that lets the user either pick the Camera app to take a new picture, or choose the Gallery app (or Photos, or a file browser) to pick an existing image. I also had to do some work in onActivityResult() to correctly receive the picture and use it depending on the choice, but I don't think that's relevant here.</p>
  
  <p>On 4.3 and below, this works great. It opens a chooser that looks something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/ehiWS.png" alt="enter image description here"></p>
  
  <p>However, on KitKat, the chooser looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/SphrX.png" alt="enter image description here"></p>
  
  <p>As you can see, it seems to be ignoring the "image/*" filter, and just giving me some generic "Documents" app for opening files.</p>
  
  <p>Obviously something has changed in KitKat, but I don't know what it is, and I can't find anyone else who has encountered this problem.</p>
  
  <p>Any ideas?</p>