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:im.neon.activity.VectorRoomActivity.java

/**
 * Launch the files selection intent//from  w w  w .j  a  v a2  s . c  om
 */
@SuppressLint("NewApi")
private void launchFileSelectionIntent() {
    enableActionBarHeader(HIDE_ACTION_BAR_HEADER);

    Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        fileIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    }
    fileIntent.setType("*/*");
    startActivityForResult(fileIntent, REQUEST_FILES_REQUEST_CODE);
}

From source file:com.android.mail.compose.ComposeActivity.java

@SuppressLint("NewApi")
private void doAttach(String type) {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    i.setType(type);/* w  w w . java2s . c o  m*/
    mAddingAttachment = true;
    startActivityForResult(Intent.createChooser(i, getText(R.string.select_attachment_type)),
            RESULT_PICK_ATTACHMENT);
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

/**
 * Manage the e2e keys import.// ww w .j av a2 s  .  c o m
 */
@SuppressLint("NewApi")
private void importKeys() {
    Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        fileIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
    }
    fileIntent.setType("*/*");
    startActivityForResult(fileIntent, REQUEST_E2E_FILE_REQUEST_CODE);
}

From source file:com.tct.mail.compose.ComposeActivity.java

@SuppressLint("NewApi")
private void doAttach(String type) {
    mAddingAttachment = true;//TS: yang.mei 2015-1-19 EMAIL BUGFIX_1441004 MOD
    //TS: zheng.zou 2015-11-30 EMAIL TASK_869664 ADD_S
    if (PermissionUtil.checkAndRequestPermissionForResult(this, Manifest.permission.READ_EXTERNAL_STORAGE,
            PermissionUtil.REQ_CODE_PERMISSION_ADD_ATTACHMENT)) { //TS: jin.dong 2015-12-17 EMAIL BUGFIX_1170083 MOD
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.addCategory(Intent.CATEGORY_OPENABLE);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        i.setType(type);/*  www . j  a va2s  . c o  m*/
        startActivityForResult(Intent.createChooser(i, getText(R.string.select_attachment_type)),
                RESULT_PICK_ATTACHMENT);

    }
    //TS: zheng.zou 2015-11-30 EMAIL TASK_869664 ADD_E
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void openGallery(final ActionListener response, int type) {
    if (!isGalleryTypeSupported(type)) {
        throw new IllegalArgumentException("Gallery type " + type + " not supported on this platform.");
    }/*from  w  ww .  ja v  a2  s  .  c  o  m*/
    if (getActivity() == null) {
        throw new RuntimeException("Cannot open galery in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
            "This is required to browse the photos")) {
        return;
    }
    if (editInProgress()) {
        stopEditing(true);
    }
    final boolean multi;
    switch (type) {
    case Display.GALLERY_ALL_MULTI:
        multi = true;
        type = Display.GALLERY_ALL;
        break;
    case Display.GALLERY_VIDEO_MULTI:
        multi = true;
        type = Display.GALLERY_VIDEO;
        break;
    case Display.GALLERY_IMAGE_MULTI:
        multi = true;
        type = Display.GALLERY_IMAGE;
        break;
    case -9998:
        multi = true;
        type = -9999;
        break;
    default:
        multi = false;
    }

    callback = new EventDispatcher();
    callback.addListener(response);
    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    if (multi) {
        galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    }
    if (type == Display.GALLERY_VIDEO) {
        galleryIntent.setType("video/*");
    } else if (type == Display.GALLERY_IMAGE) {
        galleryIntent.setType("image/*");
    } else if (type == Display.GALLERY_ALL) {
        galleryIntent.setType("image/* video/*");
    } else if (type == -9999) {
        galleryIntent = new Intent();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            galleryIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        } else {
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        }
        galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);

        // set MIME type for image
        galleryIntent.setType("*/*");
        galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES,
                Display.getInstance().getProperty("android.openGallery.accept", "*/*").split(","));
    } else {
        galleryIntent.setType("*/*");
    }
    this.getActivity().startActivityForResult(galleryIntent, multi ? OPEN_GALLERY_MULTI : OPEN_GALLERY);
}

From source file:org.telegram.ui.PassportActivity.java

private void processSelectedAttach(int which) {
    if (which == attach_photo) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 19);
            return;
        }/* w  w w. j  av  a 2  s . co  m*/
        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File image = AndroidUtilities.generatePicturePath();
            if (image != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(
                            getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image));
                    takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                }
                currentPicturePath = image.getAbsolutePath();
            }
            startActivityForResult(takePictureIntent, 0);
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else if (which == attach_gallery) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(0, false, false, null);
        fragment.setCurrentAccount(currentAccount);
        fragment.setMaxSelectedPhotos(getMaxSelectedDocuments());
        fragment.setAllowSearchImages(false);
        fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
            @Override
            public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos) {
                processSelectedFiles(photos);
            }

            @Override
            public void startPhotoSelectActivity() {
                try {
                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent, 1);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_document) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        DocumentSelectActivity fragment = new DocumentSelectActivity(false);
        fragment.setCurrentAccount(currentAccount);
        fragment.setCanSelectOnlyImageFiles(true);
        fragment.setMaxSelectedFiles(getMaxSelectedDocuments());
        fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
            @Override
            public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) {
                activity.finishFragment();
                ArrayList<SendMessagesHelper.SendingMediaInfo> arrayList = new ArrayList<>();
                for (int a = 0, count = files.size(); a < count; a++) {
                    SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                    info.path = files.get(a);
                    arrayList.add(info);
                }
                processSelectedFiles(arrayList);
            }

            @Override
            public void startDocumentSelectActivity() {
                try {
                    Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
                    if (Build.VERSION.SDK_INT >= 18) {
                        photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                    }
                    photoPickerIntent.setType("*/*");
                    startActivityForResult(photoPickerIntent, 21);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        });
        presentFragment(fragment);
    }
}