Example usage for android.provider MediaStore EXTRA_OUTPUT

List of usage examples for android.provider MediaStore EXTRA_OUTPUT

Introduction

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

Prototype

String EXTRA_OUTPUT

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

Click Source Link

Document

The name of the Intent-extra used to indicate a content resolver Uri to be used to store the requested image or video.

Usage

From source file:com.cloverstudio.spika.CameraCropActivity.java

public void startCamera() {
    // Check if camera exists
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show();
        finish();/* w  ww . ja  v a  2  s.  c  o m*/
    } else {
        try {
            long date = System.currentTimeMillis();
            String filename = DateFormat.format("yyyy-MM-dd_kk.mm.ss", date).toString() + ".jpg";
            _path = this.getExternalCacheDir() + "/" + filename;
            File file = new File(_path);
            //            File file = new File(getFileDir(getBaseContext()), filename);
            Uri outputFileUri = Uri.fromFile(file);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, CAMERA);
        } catch (Exception ex) {
            Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show();
            finish();
        }

    }
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java

/**
 * Allows the user to change the image attached to their comment or remove it
 * entirely. Prompts the user with an AlertDialog as to which option they would like
 * to select. //from   ww w.j  a v  a2 s .c o m
 * @param view The Button pressed to call editImage.
 */
public void editImage(View view) {
    if (view.getId() == R.id.attach_image_button) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle(R.string.attach_image_title);
        dialog.setMessage(R.string.attach_image_dialog);
        dialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_GALLERY);
            }
        });
        dialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                Intent intent = new Intent();
                intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                try {
                    imageFile = ImageHelper.createImageFile();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
                    startActivityForResult(Intent.createChooser(intent, "Test"), ImageHelper.REQUEST_CAMERA);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        dialog.setNeutralButton("Remove Image", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                editComment.setImage(null);
                editComment.setImageThumb(null);
            }
        });
        dialog.show();
    }
}

From source file:io.jawg.osmcontributor.ui.activities.PhotoActivity.java

private void takePicture() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        try {//  w w  w  . j av a 2s .c  o  m
            photoFile = createImageFile();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this, this.getPackageName() + ".fileprovider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_CAMERA);
        }
    }
}

From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueA.java

/**
 *          OnCreateView /* w  w w  .  ja  va2s. c  o  m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    flagStarter = true;

    FActivity_TabHost.IndexGroup = 2;
    vfrag_nIssueA = inflater.inflate(R.layout.fragment_newissue_a, container, false);

    mfrag_nIssueA = this;

    ctx = this.getActivity();

    //-------- tvUnauth ---- 
    llUnauth = (LinearLayout) vfrag_nIssueA.findViewById(R.id.llUnauth);

    Button gotoSetup = (Button) llUnauth.findViewById(R.id.bt_nia_gosetup);
    gotoSetup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();

            // Check if Activity Splash Already open
            if (Activity_Splash_Login.et_username == null) {
                Log.e("NIA", "SPLASH WAS NULL");
                startActivity(new Intent(ctx, Activity_Splash_Login.class));
            }

            getActivity().finish();
        }
    });

    //---- Spinner -----
    ArrayList<Category> mCatL_Sorted = SortCategList(Service_Data.mCategL);
    SpinnerArrString = initSpinner(mCatL_Sorted);

    sp = (Spinner) vfrag_nIssueA.findViewById(R.id.spinnerCateg);

    adapterSP = new SpinnerAdapter_NewIssueCateg(getActivity(), //--- Set spinner adapter --
            android.R.layout.simple_spinner_item, mCatL_Sorted);
    sp.setAdapter(adapterSP);

    sp.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View arg1, int arg2, long arg3) {

            if (flagStarter) {
                flagStarter = false;
            } else {
                spPosition = arg2;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    //--------- Title -----

    et_title = (EditText) vfrag_nIssueA.findViewById(R.id.etTitle_ni);

    if (et_title != null)
        if (et_title.getText().toString().length() > 0)
            titleData_STR = et_title.getText().toString();

    if (titleData_STR.length() > 0)
        et_title.setText(titleData_STR);

    //------ Description ----

    et_descr = (EditText) vfrag_nIssueA.findViewById(R.id.etDescription);
    if (et_descr != null)
        if (et_descr.getText().toString().length() > 0)
            descriptionData_STR = et_descr.getText().toString();

    //------- Bt Attach image ---
    btAttachImage = (ImageButton) vfrag_nIssueA.findViewById(R.id.btAttach_image);

    //-------- Bt Proceed -----
    btProceed = (Button) vfrag_nIssueA.findViewById(R.id.btProceed_ni_B);

    mshPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    resources = SetResources();

    //--------- Layout -------
    llnewissue_a = (LinearLayout) vfrag_nIssueA.findViewById(R.id.llnewissue_a);
    llnewissue_a.setVisibility(View.VISIBLE);

    //-------- Take Image button -------
    if (flagPictureTaken && Image_BMP != null) {

        btAttachImage.setScaleType(ScaleType.CENTER_CROP);

        try {
            btAttachImage.setImageBitmap(Image_BMP);
        } catch (Exception e) {

            // if the btAttachImage was null set Image with some delay
            btAttachImage.postDelayed(new Runnable() {
                @Override
                public void run() {
                    btAttachImage.setImageBitmap(Image_BMP);
                }
            }, 1000);
        }
        ;
    } else {
        btAttachImage.setScaleType(ScaleType.CENTER_INSIDE);
        btAttachImage.setImageResource(R.drawable.bt_custom_camera_round); //R.drawable.pattern_camera_repeater));
    }

    btAttachImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

            builder.setTitle(FActivity_TabHost.resources.getString(R.string.Attachanimage));
            builder.setIcon(android.R.drawable.ic_menu_gallery);

            // 1 select
            builder.setPositiveButton(FActivity_TabHost.resources.getString(R.string.Gallery),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            dialog.dismiss();

                            Intent intent = new Intent();
                            intent.setType("image/jpeg");
                            intent.setAction(Intent.ACTION_GET_CONTENT);
                            startActivityForResult(Intent.createChooser(intent, "Select Picture"),
                                    SELECT_PICTURE);
                        }
                    });

            // 2 Shoot
            builder.setNeutralButton(FActivity_TabHost.resources.getString(R.string.Camera),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            dialog.dismiss();
                            // 2 shoot 
                            fimg = new File(image_path_source_temp);
                            Uri uri = Uri.fromFile(fimg);

                            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

                            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
                        }
                    });

            // 3 clear 
            builder.setNegativeButton(FActivity_TabHost.resources.getString(R.string.Clear),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            //dialog.cancel();

                            flagPictureTaken = false;
                            File imagef = new File(image_path_source_temp);
                            imagef.delete();

                            dialog.dismiss();

                            //btAttachImage.setCompoundDrawablesWithIntrinsicBounds( 0, R.drawable.bt_custom_camera_round, 0,  0);
                            btAttachImage.setScaleType(ScaleType.CENTER_INSIDE);
                            btAttachImage.setImageResource(R.drawable.bt_custom_camera_round);

                            //   btAttachImage.setPadding(0, 40, 0, 0);
                        }
                    });

            builder.create();
            builder.show();
        }
    });

    //------------- button Proceed ----------
    btProceed.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View vBt) {

            // Check if title is long enough and sent
            if (et_title.getText().toString().length() > 2 && spPosition != -1
                    && et_descr.getText().toString().length() > 2) { // RRR

                titleData_STR = et_title.getText().toString();

                if (et_descr.getText().toString().length() > 0)
                    descriptionData_STR = et_descr.getText().toString();

                // Close Keyboard
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Service.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(et_title.getWindowToken(), 0);
                imm.hideSoftInputFromWindow(et_descr.getWindowToken(), 0);

                // Instantiate a new fragment.
                mfrag_nIssueB = new Fragment_NewIssueB();

                Bundle args = new Bundle();
                args.putInt("IndexSpinner", sp.getSelectedItemPosition());
                mfrag_nIssueB.setArguments(args);

                // Add the fragment to the activity, pushing this transaction
                // on to the back stack.
                FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                ft.add(mfrag_nIssueA.getId(), mfrag_nIssueB, "FTAG_NEW_ISSUE_B");
                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                ft.addToBackStack(null);
                ft.commit();
            } else if (spPosition == -1) {
                Toast.makeText(getActivity(), resources.getString(R.string.SelectaCategory), tlv).show();
            } else if (et_title.getText().toString().length() <= 2) {
                Toast.makeText(getActivity(), resources.getString(R.string.LongerTitle), tlv).show();
            } else if (et_descr.getText().toString().length() <= 2) {
                Toast.makeText(getActivity(), resources.getString(R.string.LongerDescription), tlv).show();
            }
        }
    });

    return vfrag_nIssueA;
}

From source file:io.strider.camera.CameraLauncher.java

/**
 * Take a picture with the camera.//from   w w w.ja  v  a 2s.  c  o m
 * When an image is captured or the camera view is cancelled, the result is returned
 * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult.
 *
 * The image can either be returned as a base64 string or a URI that points to the file.
 * To display base64 string in an img tag, set the source to:
 *      img.src="data:image/jpeg;base64,"+result;
 * or to display URI in an img tag
 *      img.src=result;
 *
 * @param quality           Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param returnType        Set the type of image to return.
 */
public void takePicture(int returnType, int encodingType) {

    // Save the number of images currently on disk for later
    this.numPics = queryImgDB(whichContentStore()).getCount();

    // Display camera
    Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), CameraActivity.class);
    // Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

    // Specify file so that large image is captured and returned
    File photo = createCaptureFile(encodingType);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    this.imageUri = Uri.fromFile(photo);

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
    }
    // else
    //     LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");

}

From source file:org.akvo.rsr.up.UpdateEditorActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mUser = SettingsUtil.getAuthUser(this);
    nextLocalId = SettingsUtil.ReadInt(this, ConstantUtil.LOCAL_ID_KEY, -1);

    // find which update we are editing
    // null means create a new one
    Bundle extras = getIntent().getExtras();
    projectId = extras != null ? extras.getString(ConstantUtil.PROJECT_ID_KEY) : null;
    if (projectId == null) {
        DialogUtil.errorAlert(this, R.string.noproj_dialog_title, R.string.noproj_dialog_msg);
    }//w ww .  j a  va  2s . com
    updateId = extras != null ? extras.getString(ConstantUtil.UPDATE_ID_KEY) : null;
    if (updateId == null) {
        updateId = savedInstanceState != null ? savedInstanceState.getString(ConstantUtil.UPDATE_ID_KEY) : null;
    }

    //Limit what we can write 
    InputFilter postFilter = new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            boolean keepOriginal = true;
            StringBuilder sb = new StringBuilder(end - start);
            for (int i = start; i < end; i++) {
                char c = source.charAt(i);
                if (isCharAllowed(c)) // put your condition here
                    sb.append(c);
                else
                    keepOriginal = false;
            }
            if (keepOriginal)
                return null;
            else {
                if (source instanceof Spanned) {
                    SpannableString sp = new SpannableString(sb);
                    TextUtils.copySpansFrom((Spanned) source, start, sb.length(), null, sp, 0);
                    return sp;
                } else {
                    return sb;
                }
            }
        }

        private boolean isCharAllowed(char c) {
            //                    return !Character.isSurrogate(c); //From API 19
            return !(c >= 0xD800 && c <= 0xDFFF);
        }
    };

    // get the look
    setContentView(R.layout.activity_update_editor);
    // find the fields
    progressGroup = findViewById(R.id.sendprogress_group);
    uploadProgress = (ProgressBar) findViewById(R.id.sendProgressBar);
    projTitleLabel = (TextView) findViewById(R.id.projupd_edit_proj_title);
    projupdTitleCount = (TextView) findViewById(R.id.projupd_edit_titlecount);
    projupdTitleCount.setText(Integer.toString(TITLE_LENGTH));
    projupdTitleText = (EditText) findViewById(R.id.projupd_edit_title);
    projupdTitleText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(TITLE_LENGTH), postFilter });
    projupdTitleText.addTextChangedListener(new TextWatcher() {
        //Show count of remaining characters
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            projupdTitleCount.setText(String.valueOf(TITLE_LENGTH - s.length()));
        }

        public void afterTextChanged(Editable s) {
        }
    });
    projupdDescriptionText = (EditText) findViewById(R.id.projupd_edit_description);
    projupdDescriptionText.setFilters(new InputFilter[] { postFilter });
    projupdImage = (ImageView) findViewById(R.id.image_update_detail);
    photoAndToolsGroup = findViewById(R.id.image_with_tools);
    photoAddGroup = findViewById(R.id.photo_buttons);
    photoCaptionText = (EditText) findViewById(R.id.projupd_edit_photo_caption);
    photoCaptionText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(75), postFilter });
    photoCreditText = (EditText) findViewById(R.id.projupd_edit_photo_credit);
    photoCreditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(25), postFilter });

    positionGroup = findViewById(R.id.position_group);
    latField = (TextView) findViewById(R.id.latitude);
    lonField = (TextView) findViewById(R.id.longitude);
    eleField = (TextView) findViewById(R.id.elevation);
    accuracyField = (TextView) findViewById(R.id.gps_accuracy);
    searchingIndicator = (TextView) findViewById(R.id.gps_searching);
    gpsProgress = (ProgressBar) findViewById(R.id.progress_gps);

    // Activate buttons
    btnSubmit = (Button) findViewById(R.id.btn_send_update);
    btnSubmit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            sendUpdate();
        }
    });

    btnDraft = (Button) findViewById(R.id.btn_save_draft);
    btnDraft.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            saveAsDraft(true);
        }
    });

    btnTakePhoto = (Button) findViewById(R.id.btn_take_photo);
    btnTakePhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // generate unique filename
            captureFilename = FileUtil.getExternalPhotoDir(UpdateEditorActivity.this) + File.separator
                    + "capture" + System.nanoTime() + ".jpg";
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(captureFilename)));
            startActivityForResult(takePictureIntent, photoRequest);
        }
    });

    btnAttachPhoto = (Button) findViewById(R.id.btn_attach_photo);
    btnAttachPhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, photoPick);
        }
    });

    btnDelPhoto = (Button) findViewById(R.id.btn_delete_photo);
    btnDelPhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // Forget image
            update.setThumbnailFilename(null);
            // TODO: delete image file if it was taken through this app?
            // Hide photo w tools
            showPhoto(false);
        }
    });

    btnRotRightPhoto = (Button) findViewById(R.id.btn_rotate_photo_r);
    btnRotRightPhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // Rotate image right
            rotatePhoto(true);
        }
    });

    btnGpsGeo = (Button) findViewById(R.id.btn_gps_position);
    btnGpsGeo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onGetGPSClick(view);
        }
    });

    btnPhotoGeo = (Button) findViewById(R.id.btn_photo_position);
    btnPhotoGeo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onGetPhotoLocationClick(view);
        }
    });

    dba = new RsrDbAdapter(this);
    dba.open();

    Project project = dba.findProject(projectId);
    projTitleLabel.setText(project.getTitle());

    if (updateId == null) { // create new
        update = new Update();
        update.setUuid(UUID.randomUUID().toString()); // should do sth
                                                      // better, especially
                                                      // if MAC address is
                                                      // avaliable
                                                      /*
                                                       * WifiManager wifiManager = (WifiManager)
                                                       * getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo =
                                                       * wifiManager.getConnectionInfo(); String macAddress =
                                                       * wInfo.getMacAddress(); if (macAddress == null) txt_View.append(
                                                       * "MAC Address : " + macAddress + "\n" ); else txt_View.append(
                                                       * "MAC Address : " + macAddress + "\n" ); }
                                                       */
        update.setUserId(mUser.getId());
        update.setDate(new Date());
        editable = true;
    } else {
        update = dba.findUpdate(updateId);
        if (update == null) {
            DialogUtil.errorAlert(this, R.string.noupd_dialog_title, R.string.noupd2_dialog_msg);
        } else {
            // populate fields
            editable = update.getDraft(); // This should always be true with
                                          // the current UI flow - we go to
                                          // UpdateDetailActivity if it is sent
            if (update.getTitle().equals(TITLE_PLACEHOLDER)) {
                projupdTitleText.setText(""); //placeholder is just to satisfy db
            } else {
                projupdTitleText.setText(update.getTitle());
            }
            projupdDescriptionText.setText(update.getText());
            photoCaptionText.setText(update.getPhotoCaption());
            photoCreditText.setText(update.getPhotoCredit());
            latField.setText(update.getLatitude());
            lonField.setText(update.getLongitude());
            eleField.setText(update.getElevation());
            if (update.validLatLon()) {
                positionGroup.setVisibility(View.VISIBLE);
            }
            // show preexisting image
            if (update.getThumbnailFilename() != null) {
                // btnTakePhoto.setText(R.string.btncaption_rephoto);
                ThumbnailUtil.setPhotoFile(projupdImage, update.getThumbnailUrl(),
                        update.getThumbnailFilename(), null, null, false);
                photoLocation = FileUtil.exifLocation(update.getThumbnailFilename());
                showPhoto(true);
            }
        }
    }

    // register a listener for a completion and progress intents
    broadRec = new ResponseReceiver();
    IntentFilter f = new IntentFilter(ConstantUtil.UPDATES_SENT_ACTION);
    f.addAction(ConstantUtil.UPDATES_SENDPROGRESS_ACTION);
    LocalBroadcastManager.getInstance(this).registerReceiver(broadRec, f);

    enableChanges(editable);
    btnDraft.setVisibility(editable ? View.VISIBLE : View.GONE);
    btnSubmit.setVisibility(editable ? View.VISIBLE : View.GONE);
    // btnTakePhoto.setVisibility(editable?View.VISIBLE:View.GONE);

    // Show the Up button in the action bar.
    // setupActionBar();
}

From source file:com.zlkj.dingdangwuyou.activity.CompanyInfoActivity.java

/**
 * ?/*from  w ww  . jav  a2  s. c o  m*/
 */
private void showAvatarOption() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String[] items = new String[] { "?", "" };
    builder.setTitle("").setItems(items, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent();
            switch (which) {
            case 0: // ?
                if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                    String curTime = AppTool.dateFormat(System.currentTimeMillis(), "yyyyMMddHHmmss");
                    // ???
                    File imagePath = new File(Environment.getExternalStorageDirectory() + Const.APP_IMAGE_PATH);
                    if (!imagePath.exists()) {
                        imagePath.mkdirs();
                    }
                    cameraFile = new File(imagePath.getPath(), curTime + ".jpg");

                    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile));
                    startActivityForResult(intent, Const.REQUEST_CODE_CAMERA);

                } else {
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            case 1: // 
                intent.setAction(Intent.ACTION_PICK);
                intent.setType("image/*");
                startActivityForResult(intent, Const.REQUEST_CODE_GALLERY);
                break;

            default:
                break;
            }
        }
    });

    builder.show();
}

From source file:com.stfalcon.contentmanager.ContentManager.java

public void takePhoto() {
    savedTask = CONTENT_TAKE;/*  w ww .j a v a2 s  .  c  o m*/
    if (isStoragePermissionGranted(activity, fragment)) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            try {
                boolean setPreDefinedCameraUri = isSetPreDefinedCameraUri();

                dateCameraIntentStarted = new Date();
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (setPreDefinedCameraUri) {
                    String filename = System.currentTimeMillis() + ".jpg";
                    ContentValues values = new ContentValues();
                    values.put(MediaStore.Images.Media.TITLE, filename);

                    preDefinedCameraUri = activity.getContentResolver()
                            .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, preDefinedCameraUri);
                }
                if (fragment == null) {
                    activity.startActivityForResult(intent, CONTENT_TAKE);
                } else {
                    fragment.startActivityForResult(intent, CONTENT_TAKE);
                }
            } catch (ActivityNotFoundException e) {
                pickContentListener.onError("");
            }
        } else {
            pickContentListener.onError("");
        }
    }
}

From source file:com.insthub.O2OMobile.Activity.F9_SettingActivity.java

private void showDialog() {
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.photo_dialog, null);
    mDialog = new Dialog(this, R.style.dialog);
    mDialog.setContentView(view);//  w  w  w .  j  ava  2  s  .c o  m

    mDialog.setCanceledOnTouchOutside(true);
    mDialog.show();
    LinearLayout requsetCameraLayout = (LinearLayout) view.findViewById(R.id.register_camera);
    LinearLayout requestPhotoLayout = (LinearLayout) view.findViewById(R.id.register_photo);

    requsetCameraLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();
            if (mFileDir == null) {
                mFileDir = new File(O2OMobileAppConst.FILEPATH + "img/");
                if (!mFileDir.exists()) {
                    mFileDir.mkdirs();
                }
            }
            mFileName = O2OMobileAppConst.FILEPATH + "img/" + "temp.jpg";
            mFile = new File(mFileName);
            Uri imageuri = Uri.fromFile(mFile);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageuri);
            intent.putExtra("return-data", false);
            startActivityForResult(intent, REQUEST_CAMERA);
        }
    });

    requestPhotoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();
            Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(picture, REQUEST_PHOTO);

        }
    });
}

From source file:com.luke.lukef.lukeapp.NewUserActivity.java

/**
 * Creates the intent to start camera//w  w w .j  a v a 2s. c  o  m
 */
private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go

        if (photoFile != null) {
            this.photoPath = photoFile.getAbsolutePath();
            // Continue only if the File was successfully created
            Uri photoURI = FileProvider.getUriForFile(this, "com.luke.lukef.lukeapp", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        } else {
            createImageFile();
            dispatchTakePictureIntent();
        }
    }
}