Example usage for android.content Intent EXTRA_ALLOW_MULTIPLE

List of usage examples for android.content Intent EXTRA_ALLOW_MULTIPLE

Introduction

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

Prototype

String EXTRA_ALLOW_MULTIPLE

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

Click Source Link

Document

Extra used to indicate that an intent can allow the user to select and return multiple items.

Usage

From source file:Main.java

public static Intent pickImage(int PICK_IMAGE) {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    intent.setAction(Intent.ACTION_GET_CONTENT);
    return Intent.createChooser(intent, "Select Picture");
}

From source file:com.synox.android.ui.dialog.UploadSourceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String[] allTheItems = { getString(R.string.actionbar_upload_files),
            getString(R.string.actionbar_upload_from_apps) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getTheme());
    builder.setTitle(R.string.actionbar_upload);
    builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent action = new Intent(getActivity(), UploadFilesActivity.class);
                action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, ((FileActivity) getActivity()).getAccount());
                getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_SELECT_MULTIPLE_FILES);

            } else if (item == 1) {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }/* ww  w.j  a  v a2s .  c o m*/
                getActivity().startActivityForResult(
                        Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                        FileDisplayActivity.ACTION_SELECT_CONTENT_FROM_APPS);
            }
        }
    });
    return builder.create();
}

From source file:com.cerema.cloud2.ui.dialog.UploadSourceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String[] allTheItems = { getString(R.string.actionbar_upload_files),
            getString(R.string.actionbar_upload_from_apps) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.actionbar_upload);
    builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent action = new Intent(getActivity(), UploadFilesActivity.class);
                action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, ((FileActivity) getActivity()).getAccount());
                //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                // this flow seems broken;
                // Actionbarsherlock, maybe?
                getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_SELECT_MULTIPLE_FILES);

            } else if (item == 1) {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }// w  w  w .j  av  a2  s  . co m
                getActivity().startActivityForResult(
                        Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                        FileDisplayActivity.ACTION_SELECT_CONTENT_FROM_APPS);
            }
        }
    });
    return builder.create();
}

From source file:com.owncloud.android.ui.dialog.UploadSourceDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    String[] allTheItems = { getString(R.string.actionbar_upload_files),
            getString(R.string.actionbar_upload_from_apps) };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.actionbar_upload);
    builder.setItems(allTheItems, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            if (item == 0) {
                Intent action = new Intent(getActivity(), UploadFilesActivity.class);
                action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, ((FileActivity) getActivity()).getAccount());
                //startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                // this flow seems broken;
                // Actionbarsherlock, maybe?
                getActivity().startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);

            } else if (item == 1) {
                Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                //Intent.EXTRA_ALLOW_MULTIPLE is only supported on api level 18+, Jelly Bean
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    action.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }//from   w  w w  . j  a v  a 2 s .c  o m
                //startActivityForResult(   // this flow seems broken;
                // Actionbarsherlock, maybe?
                getActivity().startActivityForResult(
                        Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                        ACTION_SELECT_CONTENT_FROM_APPS);
            }
        }
    });
    return builder.create();
}

From source file:org.sufficientlysecure.keychain.util.FileHelper.java

/** Opens the preferred installed file manager on Android and shows a toast
 * if no manager is installed. */
private static void openDocumentPreKitKat(Fragment fragment, Uri last, String mimeType, boolean multiple,
        int requestCode) {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) {
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);
    }//from   ww w  .jav a  2 s  .c o m
    intent.setData(last);
    intent.setType(mimeType);

    try {
        fragment.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        // No compatible file manager was found.
        Toast.makeText(fragment.getActivity(), R.string.no_filemanager_installed, Toast.LENGTH_SHORT).show();
    }

}

From source file:org.sufficientlysecure.keychain.util.FileHelper.java

/** Opens the storage browser on Android 4.4 or later for opening a file */
@TargetApi(Build.VERSION_CODES.KITKAT)/*from   w w  w.j a v  a 2s  .  c  o  m*/
private static void openDocumentKitKat(Fragment fragment, String mimeType, boolean multiple, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(mimeType);
    // Note: This is not documented, but works: Show the Internal Storage menu item in the drawer!
    intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, multiple);

    fragment.startActivityForResult(intent, requestCode);
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    virtualIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    virtualIntent.addCategory(Intent.CATEGORY_OPENABLE);
    virtualIntent.setType("*/*");
    virtualIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);/*  w w  w .  j a va 2s. co  m*/

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        getWindow().getDecorView().setBackground(after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
    } else {
        if (DEBUG) {
            Log.i(TAG, "mState");
        }
        buildDefaultState();
    }

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = virtualIntent.getType();
        final String title = virtualIntent.getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_GET_CONTENT) {
        final Intent moreApps = new Intent(virtualIntent);
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), moreApps);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) {
        RootsFragment.show(getFragmentManager(), null);
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = virtualIntent.getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }
}

From source file:com.farmerbb.notepad.fragment.WelcomeFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*from   ww w . j a  va2  s .  co  m*/
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_settings:
        Intent intentSettings = new Intent(getActivity(), SettingsActivity.class);
        startActivity(intentSettings);
        return true;
    case R.id.action_import:
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "text/plain", "text/html", "text/x-markdown" });
        intent.setType("*/*");

        try {
            getActivity().startActivityForResult(intent, 42);
        } catch (ActivityNotFoundException e) {
            showToast(R.string.error_importing_notes);
        }
        return true;
    case R.id.action_about:
        DialogFragment aboutFragment = new AboutDialogFragment();
        aboutFragment.show(getFragmentManager(), "about");
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.regula.documentreader.MainActivity.java

private void startPictureChoosing() {
    Intent intent = new Intent();
    intent.setType("image/*");
    if (Build.VERSION.SDK_INT >= 18) {
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    }//from ww  w .  ja  va 2  s . co  m
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
}

From source file:com.commonsware.android.tte.MainActivity.java

private void openDocument(boolean allowMultiple) {
    Intent i = new Intent().setType("text/*").setAction(Intent.ACTION_OPEN_DOCUMENT)
            .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple).addCategory(Intent.CATEGORY_OPENABLE);

    startActivityForResult(i, REQUEST_OPEN);
}