Example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE

List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE

Introduction

In this page you can find the example usage for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Prototype

String ACTION_IMAGE_CAPTURE

To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.

Click Source Link

Document

Standard Intent action that can be sent to have the camera application capture an image and return it.

Usage

From source file:com.dwdesign.tweetings.util.Utils.java

public static Intent createTakePhotoIntent(Uri uri) {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    return intent;
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case android.R.id.home:
        finishFragment();// www .  j  a  v a  2 s . co  m
        break;
    case R.id.attach_photo: {
        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File image = Utilities.generatePicturePath();
            if (image != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                currentPicturePath = image.getAbsolutePath();
            }
            startActivityForResult(takePictureIntent, 0);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_gallery: {
        try {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, 1);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_video: {
        try {
            Intent pickIntent = new Intent();
            pickIntent.setType("video/*");
            pickIntent.setAction(Intent.ACTION_GET_CONTENT);
            pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
            Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            File video = Utilities.generateVideoPath();
            if (video != null) {
                if (android.os.Build.VERSION.SDK_INT > 16) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
                }
                takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
                currentPicturePath = video.getAbsolutePath();
            }
            Intent chooserIntent = Intent.createChooser(pickIntent, "");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent });

            startActivityForResult(chooserIntent, 2);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_location: {
        if (!isGoogleMapsInstalled()) {
            return true;
        }
        LocationActivity fragment = new LocationActivity();
        ((ApplicationActivity) parentActivity).presentFragment(fragment, "location", false);
        break;
    }
    case R.id.attach_document: {
        DocumentSelectActivity fragment = new DocumentSelectActivity();
        fragment.delegate = this;
        ((ApplicationActivity) parentActivity).presentFragment(fragment, "document", false);
        break;
    }
    }
    return true;
}

From source file:com.irccloud.android.activity.MainActivity.java

private void insertPhoto() {
    if (buffer == null)
        return;//w  w  w  .  j  a v a  2 s.com

    AlertDialog.Builder builder;
    AlertDialog dialog;
    builder = new AlertDialog.Builder(this);
    builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
    String[] items = (Build.VERSION.SDK_INT < 19 || !NetworkConnection.getInstance().uploadsAvailable())
            ? new String[] { "Take a Photo", "Choose Existing", "Start a Pastebin", "Pastebins" }
            : new String[] { "Take a Photo", "Choose Existing Photo", "Choose Existing Document",
                    "Start a Pastebin", "Pastebins" };
    if (NetworkConnection.getInstance().uploadsAvailable()) {
        items = Arrays.copyOf(items, items.length + 1);
        items[items.length - 1] = "File Uploads";
    }

    final String[] dialogItems = items;

    builder.setItems(dialogItems, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent i;
            if (buffer != null) {
                switch (dialogItems[which]) {
                case "Take a Photo":
                    try {
                        File imageDir = new File(Environment.getExternalStorageDirectory(), "IRCCloud");
                        imageDir.mkdirs();
                        new File(imageDir, ".nomedia").createNewFile();
                        imageCaptureURI = Uri
                                .fromFile(File.createTempFile("irccloudcapture", ".jpg", imageDir));
                        i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageCaptureURI);
                        startActivityForResult(i, REQUEST_CAMERA);
                    } catch (IOException e) {
                    }
                    break;
                case "Choose Existing":
                case "Choose Existing Photo":
                    i = new Intent(Intent.ACTION_GET_CONTENT,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    i.addCategory(Intent.CATEGORY_OPENABLE);
                    i.setType("image/*");
                    startActivityForResult(Intent.createChooser(i, "Select Picture"), REQUEST_PHOTO);
                    break;
                case "Choose Existing Document":
                    i = new Intent(Intent.ACTION_GET_CONTENT);
                    i.addCategory(Intent.CATEGORY_OPENABLE);
                    i.setType("*/*");
                    startActivityForResult(Intent.createChooser(i, "Select A Document"), REQUEST_DOCUMENT);
                    break;
                case "Start a Pastebin":
                    show_pastebin_prompt();
                    break;
                case "Pastebins":
                    i = new Intent(MainActivity.this, PastebinsActivity.class);
                    startActivity(i);
                    break;
                case "File Uploads":
                    i = new Intent(MainActivity.this, UploadsActivity.class);
                    i.putExtra("cid", buffer.cid);
                    i.putExtra("to", buffer.name);
                    i.putExtra("msg", messageTxt.getText().toString());
                    startActivityForResult(i, REQUEST_UPLOADS);
                    break;
                }
            }
            dialog.dismiss();
        }
    });
    dialog = builder.create();
    dialog.setOwnerActivity(MainActivity.this);
    dialog.show();
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private void showFileAttach() {
    final List<Intent> allIntents = new ArrayList<Intent>();

    // all openable...
    Intent contentIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentIntent.setType(SafeSlingerConfig.MIMETYPE_ADD_ATTACH);
    contentIntent.addCategory(Intent.CATEGORY_OPENABLE);

    // camera// ww  w.ja va 2s. com
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    SafeSlinger.setTempCameraFileUri(SSUtil.makeCameraOutputUri());
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, SafeSlinger.getTempCameraFileUri());
    allIntents.add(cameraIntent);

    // audio recorder
    Intent recorderIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    recorderIntent.putExtra(MediaStore.EXTRA_OUTPUT, SSUtil.makeRecorderOutputUri());
    allIntents.add(recorderIntent);

    // our custom browser
    if (SSUtil.isExternalStorageReadable()) {
        Intent filePickIntent = new Intent(HomeActivity.this, FilePickerActivity.class);
        LabeledIntent fileIntent = new LabeledIntent(filePickIntent, filePickIntent.getPackage(),
                R.string.menu_FileManager, R.drawable.ic_menu_directory);
        allIntents.add(fileIntent);
    }

    // Chooser of file system options.
    Intent chooserIntent = Intent.createChooser(contentIntent, getString(R.string.title_ChooseFileLoad));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[] {}));
    startActivityForResult(chooserIntent, VIEW_FILEATTACH_ID);
}

From source file:kr.wdream.ui.ChatActivity.java

private void processSelectedAttach(int which) {
    if (which == attach_photo || which == attach_gallery || which == attach_document || which == attach_video) {
        String action;// w  w  w .  j  a  v a2s.  c om
        if (currentChat != null) {
            if (currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
                if (which == attach_photo || which == attach_gallery) {
                    action = "bigchat_upload_photo";
                } else {
                    action = "bigchat_upload_document";
                }
            } else {
                if (which == attach_photo || which == attach_gallery) {
                    action = "chat_upload_photo";
                } else {
                    action = "chat_upload_document";
                }
            }
        } else {
            if (which == attach_photo || which == attach_gallery) {
                action = "pm_upload_photo";
            } else {
                action = "pm_upload_document";
            }
        }
        if (!MessagesController.isFeatureEnabled(action, ChatActivity.this)) {
            return;
        }
    }

    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;
        }
        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("tmessages", 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(false,
                currentEncryptedChat == null
                        || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46,
                true, ChatActivity.this);
        fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
            @Override
            public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions,
                    ArrayList<ArrayList<TLRPC.InputDocument>> masks,
                    ArrayList<MediaController.SearchImage> webPhotos) {
                SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject,
                        captions, masks);
                SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id, replyingMessageObject);
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
            }

            @Override
            public void startPhotoSelectActivity() {
                try {
                    Intent videoPickerIntent = new Intent();
                    videoPickerIntent.setType("video/*");
                    videoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
                    videoPickerIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536));

                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    Intent chooserIntent = Intent.createChooser(photoPickerIntent, null);
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { videoPickerIntent });

                    startActivityForResult(chooserIntent, 1);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }

            @Override
            public boolean didSelectVideo(String path) {
                if (Build.VERSION.SDK_INT >= 16) {
                    return !openVideoEditor(path, true, true);
                } else {
                    SendMessagesHelper.prepareSendingVideo(path, 0, 0, 0, 0, null, dialog_id,
                            replyingMessageObject, null);
                    showReplyPanel(false, null, null, null, false, true);
                    DraftQuery.cleanDraft(dialog_id, true);
                    return true;
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_video) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 20);
            return;
        }
        try {
            Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            File video = AndroidUtilities.generateVideoPath();
            if (video != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(
                            getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", video));
                    takeVideoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else if (Build.VERSION.SDK_INT >= 18) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
                }
                takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536));
                currentPicturePath = video.getAbsolutePath();
            }
            startActivityForResult(takeVideoIntent, 2);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    } else if (which == attach_location) {
        if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) {
            return;
        }
        LocationActivity fragment = new LocationActivity();
        fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
            @Override
            public void didSelectLocation(TLRPC.MessageMedia location) {
                SendMessagesHelper.getInstance().sendMessage(location, dialog_id, replyingMessageObject, null,
                        null);
                moveScrollToLastMessage();
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
                if (paused) {
                    scrollToTopOnResume = true;
                }
            }
        });
        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();
        fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
            @Override
            public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) {
                activity.finishFragment();
                SendMessagesHelper.prepareSendingDocuments(files, files, null, null, dialog_id,
                        replyingMessageObject);
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
            }

            @Override
            public void startDocumentSelectActivity() {
                try {
                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("*/*");
                    startActivityForResult(photoPickerIntent, 21);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_audio) {
        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;
        }
        AudioSelectActivity fragment = new AudioSelectActivity();
        fragment.setDelegate(new AudioSelectActivity.AudioSelectActivityDelegate() {
            @Override
            public void didSelectAudio(ArrayList<MessageObject> audios) {
                SendMessagesHelper.prepareSendingAudioDocuments(audios, dialog_id, replyingMessageObject);
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
            }
        });
        presentFragment(fragment);
    } else if (which == attach_contact) {
        if (Build.VERSION.SDK_INT >= 23) {
            if (getParentActivity().checkSelfPermission(
                    Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, 5);
                return;
            }
        }
        try {
            Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
            startActivityForResult(intent, 31);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    }
}

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

@Override
public void capturePhoto(ActionListener response) {
    if (getActivity() == null) {
        throw new RuntimeException("Cannot capture photo in background mode");
    }/*from  w  w  w.  j  a v  a  2 s. c om*/
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to take a picture")) {
        return;
    }
    if (getRequestedPermissions().contains(Manifest.permission.CAMERA)) {
        // Normally we don't need to request the CAMERA permission since we use
        // the ACTION_IMAGE_CAPTURE intent, which handles permissions itself.
        // BUT: If the camera permission is included in the Manifest file, the 
        // intent will defer to the app's permissions, and on Android 6, 
        // the permission is denied unless we do the runtime check for permission.
        // See https://github.com/codenameone/CodenameOne/issues/2409#issuecomment-391696058
        if (!checkForPermission(Manifest.permission.CAMERA, "This is required to take a picture")) {
            return;
        }
    }
    callback = new EventDispatcher();
    callback.addListener(response);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    File newFile = getOutputMediaFile(false);
    newFile.getParentFile().mkdirs();
    newFile.getParentFile().setWritable(true, false);
    //Uri imageUri = Uri.fromFile(newFile);
    Uri imageUri = FileProvider.getUriForFile(getContext(), getContext().getPackageName() + ".provider",
            newFile);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);

    String lastImageID = getLastImageId();
    Storage.getInstance().writeObject("imageUri", newFile.getAbsolutePath() + ";" + lastImageID);

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    if (Build.VERSION.SDK_INT < 21) {
        List<ResolveInfo> resInfoList = getContext().getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            getContext().grantUriPermission(packageName, imageUri,
                    Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    }

    getActivity().startActivityForResult(intent, CAPTURE_IMAGE);
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

private void choosePicture() {
    if (cameraDialog == null) {
        LayoutInflater dialogInflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View dialogView = dialogInflater.inflate(R.layout.dialog_camera_gallery, null);
        TextView camera = (TextView) dialogView.findViewById(R.id.dialog_camera);
        TextView gallery = (TextView) dialogView.findViewById(R.id.dialog_gallery);
        TFCache.apply(activity, camera, TFCache.TF_SPEAKALL);
        TFCache.apply(activity, gallery, TFCache.TF_SPEAKALL);
        final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                .setCancelable(true);/*from w w  w.j av  a 2  s . c o m*/
        cameraDialog = dialogBuilder.show();
        camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cameraDialog.dismiss();
                dontClose = true;
                ((MainActivity) activity).dontClose = true;
                hideKeyBoard();
                File imagesFolder = new File(
                        Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
                imagesFolder.mkdirs();
                menuAdjunt = false;
                adjuntLayout.setVisibility(View.GONE);
                dateToCamera = Calendar.getInstance().getTimeInMillis();
                File image = new File(imagesFolder, dateToCamera + ".png");
                Uri uriSavedImage = Uri.fromFile(image);
                pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                startActivityForResult(pictureActionIntent, 23);
            }
        });
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cameraDialog.dismiss();
                dontClose = true;
                ((MainActivity) activity).dontClose = true;
                hideKeyBoard();
                menuAdjunt = false;
                adjuntLayout.setVisibility(View.GONE);
                pictureActionIntent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(pictureActionIntent, 1);
            }
        });
        cameraDialog.setCanceledOnTouchOutside(true);
    } else {
        cameraDialog.show();
    }
}

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. ja va 2 s. c  o 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);
    }
}