Example usage for android.content Intent CATEGORY_OPENABLE

List of usage examples for android.content Intent CATEGORY_OPENABLE

Introduction

In this page you can find the example usage for android.content Intent CATEGORY_OPENABLE.

Prototype

String CATEGORY_OPENABLE

To view the source code for android.content Intent CATEGORY_OPENABLE.

Click Source Link

Document

Used to indicate that an intent only wants URIs that can be opened with ContentResolver#openFileDescriptor(Uri,String) .

Usage

From source file:com.snappy.CameraCropActivity.java

private void getImageIntents() {
    /*// ww w .  j  av  a2s .c  om
     * if (getIntent().hasExtra("trio")) { _trio = true; _groupId =
     * getIntent().getStringExtra("groupId"); _planner =
     * getIntent().getBooleanExtra("planner", false); } else { _trio =
     * false; _planner = false; _groupId = ""; }
     */
    if (getIntent().getStringExtra("type").equals("gallery")) {

        //this is used to solve the selected path for android 19, kitkat o superior
        if (Build.VERSION.SDK_INT < 19) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            this.startActivityForResult(intent, GALLERY);
        } else {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            this.startActivityForResult(intent, GALLERY);
        }

        mIsCamera = false;

    } else {
        try {
            startCamera();
            mIsCamera = true;
        } catch (UnsupportedOperationException ex) {
            ex.printStackTrace();
            Toast.makeText(getBaseContext(), "UnsupportedOperationException", Toast.LENGTH_SHORT).show();
        }
    }
    if (getIntent().getBooleanExtra("profile", false) == true) {
        mForProfile = true;
    } else {
        mForProfile = false;
    }
    if (getIntent().getBooleanExtra("createGroup", false) == true) {
        mForGroup = true;
    } else {
        mForGroup = false;
    }
    if (getIntent().getBooleanExtra("groupUpdate", false) == true) {
        mForGroupUpdate = true;
    } else {
        mForGroupUpdate = false;
    }
}

From source file:com.kdao.cmpe235_project.UploadActivity.java

private void initUI() {
    /**//from w ww . java  2  s  . c  o  m
     * This adapter takes the data in transferRecordMaps and displays it,
     * with the keys of the map being related to the columns in the adapter
     */
    simpleAdapter = new SimpleAdapter(this, transferRecordMaps, R.layout.record_item,
            new String[] { "checked", "fileName", "progress", "bytes", "state", "percentage" },
            new int[] { R.id.radioButton1, R.id.textFileName, R.id.progressBar1, R.id.textBytes, R.id.textState,
                    R.id.textPercentage });
    simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            switch (view.getId()) {
            case R.id.radioButton1:
                RadioButton radio = (RadioButton) view;
                radio.setChecked((Boolean) data);
                return true;
            case R.id.textFileName:
                TextView fileName = (TextView) view;
                fileName.setText((String) data);
                return true;
            case R.id.progressBar1:
                ProgressBar progress = (ProgressBar) view;
                progress.setProgress((Integer) data);
                return true;
            case R.id.textBytes:
                TextView bytes = (TextView) view;
                bytes.setText((String) data);
                return true;
            case R.id.textState:
                TextView state = (TextView) view;
                state.setText(((TransferState) data).toString());
                return true;
            case R.id.textPercentage:
                TextView percentage = (TextView) view;
                percentage.setText((String) data);
                return true;
            }
            return false;
        }
    });
    setListAdapter(simpleAdapter);

    // Updates checked index when an item is clicked
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) {

            if (checkedIndex != pos) {
                transferRecordMaps.get(pos).put("checked", true);
                if (checkedIndex >= 0) {
                    transferRecordMaps.get(checkedIndex).put("checked", false);
                }
                checkedIndex = pos;
                updateButtonAvailability();
                simpleAdapter.notifyDataSetChanged();
            }
        }
    });

    //btnUploadFile = (Button) findViewById(R.id.buttonUploadFile);
    btnUploadImage = (Button) findViewById(R.id.buttonUploadImage);
    btnUploadAudio = (Button) findViewById(R.id.buttonUploadAudio);
    btnUploadVideo = (Button) findViewById(R.id.buttonUploadVideo);
    btnPause = (Button) findViewById(R.id.buttonPause);
    btnResume = (Button) findViewById(R.id.buttonResume);
    btnCancel = (Button) findViewById(R.id.buttonCancel);
    btnDelete = (Button) findViewById(R.id.buttonDelete);
    btnPauseAll = (Button) findViewById(R.id.buttonPauseAll);
    btnCancelAll = (Button) findViewById(R.id.buttonCancelAll);

    btnUploadImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                System.out.println(">>>>> Start uploading photos... <<<<<<<");
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/photo";
                intent.setType("image/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }
    });

    btnUploadAudio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/audio";
                intent.setType("audio/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }

    });

    btnUploadVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTreeSelected) {
                Intent intent = new Intent();
                if (Build.VERSION.SDK_INT >= 19) {
                    // For Android versions of KitKat or later, we use a
                    // different intent to ensure
                    // we can get the file path from the returned intent URI
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }
                APIurl = "/tree/" + treeId + "/video";
                intent.setType("video/*");
                startActivityForResult(intent, 0);
            } else {
                Toast.makeText(getApplicationContext(), Config.UPLOAD_NOTREE_ERR, Toast.LENGTH_LONG).show();
            }
        }
    });

    btnPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure the user has selected a transfer
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                Boolean paused = transferUtility.pause(observers.get(checkedIndex).getId());
                /**
                 * If paused does not return true, it is likely because the
                 * user is trying to pause an upload that is not in a
                 * pausable state (For instance it is already paused, or
                 * canceled).
                 */
                if (!paused) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_PAUSE_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnResume.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure the user has selected a transfer
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                TransferObserver resumed = transferUtility.resume(observers.get(checkedIndex).getId());
                // Sets a new transfer listener to the original observer.
                // This will overwrite existing listener.
                observers.get(checkedIndex).setTransferListener(new UploadListener());
                /**
                 * If resume returns null, it is likely because the transfer
                 * is not in a resumable state (For instance it is already
                 * running).
                 */
                if (resumed == null) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_RESUME_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure a transfer is selected
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                Boolean canceled = transferUtility.cancel(observers.get(checkedIndex).getId());
                /**
                 * If cancel returns false, it is likely because the
                 * transfer is already canceled
                 */
                if (!canceled) {
                    Toast.makeText(UploadActivity.this, Config.UPLOAD_TRANSFER_ERR, Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    btnDelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Make sure a transfer is selected
            if (checkedIndex >= 0 && checkedIndex < observers.size()) {
                transferUtility.deleteTransferRecord(observers.get(checkedIndex).getId());
                observers.remove(checkedIndex);
                transferRecordMaps.remove(checkedIndex);
                checkedIndex = INDEX_NOT_CHECKED;
                updateButtonAvailability();
                updateList();
            }
        }
    });

    btnPauseAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transferUtility.pauseAllWithType(TransferType.UPLOAD);
        }
    });

    btnCancelAll.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transferUtility.cancelAllWithType(TransferType.UPLOAD);
        }
    });

    updateButtonAvailability();
}

From source file:geert.stef.sm.beheerautokm.Overview.java

public void addGalleryImage(View view) {
    if (view.getId() == R.id.btnAddGalleryImage) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(intent, REQUEST_CODE_SELECT);
    }/*from w w  w  .ja v a 2  s . c  om*/
}

From source file:com.logilite.vision.camera.CameraLauncher.java

/**
 * Get image from photo library.//from   w  w w.j  ava 2 s.c  o  m
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
public void getImage(int srcType, int returnType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
    }

    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this,
                Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1);
    }
}

From source file:com.juegoteca.actividades.Opciones.java

/**
 * Shows the simplified settings UI if the device configuration if the
 * device configuration dictates that a simplified, single-pane UI should be
 * shown./*from  w ww .j a  v  a2s .  co m*/
 */
@SuppressWarnings("deprecation")
private void setupSimplePreferencesScreen() {
    if (!isSimplePreferences(this)) {
        return;
    }

    final SharedPreferences settings = getSharedPreferences("UserInfo", 0);

    // In the simplified UI, fragments are not used at all and we instead
    // use the older PreferenceActivity APIs.

    addPreferencesFromResource(R.xml.pref_container);

    // Add 'general' preferences.
    PreferenceCategory fakeHeader = new PreferenceCategory(this);
    fakeHeader.setTitle(R.string.pref_header_general);
    getPreferenceScreen().addPreference(fakeHeader);
    addPreferencesFromResource(R.xml.pref_general);

    CheckBoxPreference preferenciaOrden = (CheckBoxPreference) findPreference("orden_ultimos_anadidos");
    preferenciaOrden.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("orden_ultimos_fecha_compra", true);
                editor.commit();
            } else {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("orden_ultimos_fecha_compra", false);
                editor.commit();
            }
            return true;
        }
    });

    ListPreference preferenciaModeda = (ListPreference) findPreference("currencys");
    preferenciaModeda.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {

            SharedPreferences.Editor editor = settings.edit();
            editor.putString("currency", newValue.toString());
            editor.commit();

            return true;
        }
    });

    CheckBoxPreference preferenciaDetalle = (CheckBoxPreference) findPreference("detalle_imagen");
    preferenciaDetalle.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue.toString().equals("true")) {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("detalle_imagen", true);
                editor.commit();
            } else {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("detalle_imagen", false);
                editor.commit();
            }
            return true;
        }
    });

    SwitchPreference preferenciaTwitter = (SwitchPreference) findPreference("twitter");
    preferenciaTwitter.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue instanceof Boolean) {
                boolean isChecked = (boolean) newValue;
                if (isChecked) {
                    Intent intent = new Intent(getApplicationContext(), TwitterActivity.class);
                    startActivity(intent);
                    return true;
                }
            }
            return true;
        }
    });

    // Add 'data and sync' preferences, and a corresponding header.
    PreferenceCategory fakeHeader2 = new PreferenceCategory(this);
    fakeHeader2.setTitle(R.string.pref_header_data);
    getPreferenceScreen().addPreference(fakeHeader2);
    addPreferencesFromResource(R.xml.pref_datos_seguridad);

    // Establece las acciones al hacer click en las preferencias
    Preference preferenciaCopiaExportar = findPreference("exportar_copia_seguridad");
    preferenciaCopiaExportar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            Toast t;
            if (!utilidades.baseDatosEsVacia()) {
                new CopiaSeguridadFichero().execute();
            } else {
                t = Toast.makeText(getApplicationContext(), getString(R.string.no_data_backup),
                        Toast.LENGTH_SHORT);
                t.show();
            }
            return true;
        }
    });

    Preference preferenciaCopiaImportar = findPreference("importar_restaurar_seguridad");

    preferenciaCopiaImportar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {

            AlertDialog.Builder builder = new AlertDialog.Builder(Opciones.this);
            builder.setMessage(R.string.alerta_restaurar_texto).setTitle(R.string.alerta_restaurar_titulo);
            builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("application/zip");
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    startActivityForResult(Intent.createChooser(intent, "Escoja el fichero de copia..."),
                            FILE_SELECT_CODE);

                }
            });

            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog
                    return;
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();

            return true;
        }
    });

    Preference preferenciaBorrar = findPreference("borrar_todo");
    preferenciaBorrar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            utilidades.borrarTodosDatos(true);
            return true;
        }
    });

    // Add 'otros' preferences.
    PreferenceCategory fakeHeader3 = new PreferenceCategory(this);
    fakeHeader3.setTitle(R.string.pref_header_otros);
    getPreferenceScreen().addPreference(fakeHeader3);
    addPreferencesFromResource(R.xml.pref_otros);

    Resources res = getResources();
    // String versionName = res.getString(R.string.app_version);

    String versionName = "";
    try {
        versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        // versionName = res.getString(R.string.app_version);
    }

    String version = res.getString(R.string.pref_title_version, versionName);
    Preference preferenciaInicioSesion = findPreference("about");
    preferenciaInicioSesion.setTitle(version);

    Preference preferenciaLicencia = findPreference("licenses");
    preferenciaLicencia.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getApplicationContext(), AcercaDe.class);
            startActivity(intent);
            return true;
        }
    });

}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {/*from   ww w  .ja v a  2s. com*/
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}

From source file:cc.metapro.openct.myclass.ClassActivity.java

private void showFilerChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {/*  w  ww.  j  a v  a2s .  c o  m*/
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(this, R.string.fail_file_chooser, Toast.LENGTH_LONG).show();
    }
}

From source file:org.skt.runtime.RuntimeChromeClient.java

public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) {
    uploadMessage = uploadFile;//from   ww w  .  j av a  2 s  .c o  m
    ;
    Intent intent = null;

    //[20130723][chisu]<input type="file"></input>
    if (acceptType.equals("")) {
        //[20120614][chisu]call gallery 
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");

        Intent chooser = createChooserIntent(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE),
                new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE),
                new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION));
        chooser.putExtra(Intent.EXTRA_INTENT, intent);

        ctx.startActivityForResult(chooser, FILE_RESULTCODE);
    }
    //[20130723][chisu]<input type="file" name="image" accept="image/*" capture>
    else if (acceptType.equals("image/*")) {
        intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        ctx.startActivityForResult(intent, IMAGE_RESULTCODE);
    }
    //[20130723][chisu]<input type="file" name="video" accept="video/*" capture>
    else if (acceptType.equals("video/*")) {
        intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
        ctx.startActivityForResult(intent, VIDEO_RESULTCODE);
    }
    //[20130723][chisu]<input type="file" name="audio" accept="audio/*" capture>
    else if (acceptType.equals("audio/*")) {
        intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
        ctx.startActivityForResult(intent, AUDIO_RESULTCODE);
    }
    //[20131011][chisu]FIXME:<input type="file" name="image" accept="image/S4" capture>
    else if (acceptType.equals("image/S4")) {
        //[20120614][chisu]call gallery 
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");

        Intent chooser = createChooserIntent(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE));
        chooser.putExtra(Intent.EXTRA_INTENT, intent);

        ctx.startActivityForResult(chooser, FILE_RESULTCODE);
    }
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

public void imageOpen(Fragment f, final int REQUEST_CAMERA, final int SELECT_FILE) {

    GeneralHelper.getInstance(MainActivity.this).setTempFragment(f);
    final CharSequence[] items = { "Take Photo", "Choose from Library", "Cancel" };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Add Photo!");
    builder.setItems(items, new DialogInterface.OnClickListener() {

        @Override//from w  ww .  ja  va2s .  c o m
        public void onClick(DialogInterface dialog, int item) {
            if (items[item].equals("Take Photo")) {

                java.io.File imageFile = new File(
                        (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/."
                                + Constants.APPNAME + "/" + System.currentTimeMillis() + ".jpeg"));

                PreferencesManager.setPreferenceByKey(MainActivity.this, "IMAGEWWC",
                        imageFile.getAbsolutePath());
                //
                imageFilePath = imageFile;
                imageFileUri = Uri.fromFile(imageFile);
                Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
                startActivityForResult(i, REQUEST_CAMERA);

            } else if (items[item].equals("Choose from Library")) {
                if (Build.VERSION.SDK_INT < 19) {
                    Intent intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
                } else {
                    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setType("image/*");
                    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
                }

            } else if (items[item].equals("Cancel")) {
                dialog.dismiss();
            }
        }
    });
    builder.show();
}

From source file:io.ingame.squarecamera.CameraLauncher.java

/**
 * Get image from photo library.//from  w w w  .  ja  v  a  2  s  .  c  o  m
 *
 * @param srcType           The album to get image from.
 * @param returnType        Set the type of image to return.
 * @param encodingType
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
// TODO: Images from kitkat filechooser not going into crop function
public void getImage(int srcType, int returnType, int encodingType) {
    Intent intent = new Intent();
    String title = GET_PICTURE;
    croppedUri = null;
    if (this.mediaType == PICTURE) {
        intent.setType("image/*");
        if (this.allowEdit) {
            intent.setAction(Intent.ACTION_PICK);
            intent.putExtra("crop", "true");
            if (targetWidth > 0) {
                intent.putExtra("outputX", targetWidth);
            }
            if (targetHeight > 0) {
                intent.putExtra("outputY", targetHeight);
            }
            if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
            }
            File photo = createCaptureFile(encodingType);
            croppedUri = Uri.fromFile(photo);
            setOutputUri(intent, croppedUri);
        } else {
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
        }
    } else if (this.mediaType == VIDEO) {
        intent.setType("video/*");
        title = GET_VIDEO;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    } else if (this.mediaType == ALLMEDIA) {
        // I wanted to make the type 'image/*, video/*' but this does not work on all versions
        // of android so I had to go with the wildcard search.
        intent.setType("*/*");
        title = GET_All;
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this,
                Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1);
    }
}