List of usage examples for android.provider MediaStore ACTION_IMAGE_CAPTURE
String ACTION_IMAGE_CAPTURE
To view the source code for android.provider MediaStore ACTION_IMAGE_CAPTURE.
Click Source Link
From source file:com.openatk.rockapp.MainActivity.java
@Override public void RockTakePicture(int id, String filepath, String filename) { // Get the new image path File path = new File(filepath); path.mkdirs();/* w w w. j a va2 s . co m*/ File image = new File(path, filename); try { image.createNewFile(); } catch (IOException e) { Log.w("RockAppActivity", "Could not make file for image. " + image.getAbsolutePath() + " " + e.toString()); return; } // Put together image capture intent Intent takePic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); takePic.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); // Fire intent startActivityForResult(Intent.createChooser(takePic, "Capture Image"), REQUEST_PICTURE); }
From source file:com.parttime.activity.ChatActivity.java
/** * ?//from w ww . j ava 2 s . com */ public void selectPicFromCamera() { if (!CommonUtils.isExitsSdcard()) { Toast.makeText(getApplicationContext(), "SD????", 0).show(); return; } cameraFile = new File(PathUtil.getInstance().getImagePath(), PartTimeApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg"); cameraFile.getParentFile().mkdirs(); startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA); }
From source file:doext.easemob.activity.ChatActivity.java
/** * ?//w ww .j ava 2s. c o m */ public void selectPicFromCamera() { if (!CommonUtils.isExitsSdcard()) { String st = getResources() .getString(DoResourcesHelper.getIdentifier("sd_card_does_not_exist", "string", this)); Toast.makeText(getApplicationContext(), st, 0).show(); return; } cameraFile = new File( PathUtil.getInstance().getImagePath(), /* DemoApplication.getInstance().getUserName()*/ +System.currentTimeMillis() + ".jpg"); cameraFile.getParentFile().mkdirs(); startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA); }
From source file:com.juick.android.ThreadActivity.java
public void onClick(DialogInterface dialog, int which) { Intent intent;//w ww . j a v a2 s .com switch (which) { case 0: intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, null), ACTIVITY_ATTACHMENT_IMAGE); break; case 1: intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); boolean useTempFileForCapture = sp.getBoolean("useTempFileForCapture", true); if (useTempFileForCapture) { File file = NewMessageActivity.getPhotoCaptureFile(); file.delete(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); } else { intent.putExtra(MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); } startActivityForResult(intent, ACTIVITY_ATTACHMENT_IMAGE); break; case 2: intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("video/*"); startActivityForResult(Intent.createChooser(intent, null), ACTIVITY_ATTACHMENT_VIDEO); break; case 3: intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, ACTIVITY_ATTACHMENT_VIDEO); break; } }
From source file:com.ieeton.user.activity.ChatActivity.java
/** * ?/* w w w.ja va 2 s.c o m*/ */ public void selectPicFromCamera() { if (!CommonUtils.isExitsSdcard()) { Toast.makeText(getApplicationContext(), R.string.no_sdcard_for_capture, Toast.LENGTH_SHORT).show(); return; } cameraFile = new File(PathUtil.getInstance().getImagePath(), IeetonApplication.getInstance().getUserName() + System.currentTimeMillis() + ".jpg"); cameraFile.getParentFile().mkdirs(); startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA); }
From source file:com.alivenet.dmv.driverapplication.fragment.MyAccount.java
public static void takePicture(final Activity context) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); try {/*from ww w . j a v a 2s .c o m*/ Uri mImageCaptureUri = null; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { mImageCaptureUri = Uri.fromFile(AppData.getSingletonObject().getmFileTemp()); } else { mImageCaptureUri = InternalStorageContentProvider.CONTENT_URI; } intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri); intent.putExtra("return-data", true); context.startActivityForResult(intent, ConstantUtil.REQUEST_CODE_TAKE_PICTURE); } catch (ActivityNotFoundException e) { Log.d(ConstantUtil.BLANK_TEXT, "cannot take picture", e); } }
From source file:com.feytuo.chat.activity.ChatActivity.java
/** * ?//from www . j a v a 2s .c om */ public void selectPicFromCamera() { if (!CommonUtils.isExitsSdcard()) { Toast.makeText(getApplicationContext(), "SD????", 0).show(); return; } cameraFile = new File(PathUtil.getInstance().getImagePath(), App.getInstance().getUserName() + System.currentTimeMillis() + ".jpg"); cameraFile.getParentFile().mkdirs(); startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA); }
From source file:com.stikyhive.stikyhive.ChattingActivity.java
public void showPhoto() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String[] strArray = { "Take photo", "Choose from Gallery" }; builder.setTitle("Select Photo").setItems(strArray, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' argument contains the index position // of the selected item switch (which) { case 0: Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); /*****//from w w w . ja v a 2 s . c o m * Define the file-name to save photo taken by * Camera activity *******/ String fileName = "Camera_Example.jpg"; // Create parameters for Intent with filename ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera"); /****** * imageUri is the current activity attribute, * define and save it for later usage *****/ imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); // start the image capture Intent startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); Log.i("Camera ", " Testing..."); break; case 1: // start GalleryUtil Activity to choose photo from // Gallery Intent gallery_Intent = new Intent("com.arctech.GALLERYUTIL"); gallery_Intent.putExtra("type", "image"); startActivityForResult(gallery_Intent, GALLERY_ACTIVITY_CODE); break; default: break; } } }); builder.create(); builder.show(); }
From source file:com.aidigame.hisun.imengstar.huanxin.ChatActivity.java
/** * ?/*from ww w .j a va 2 s . c o m*/ */ public void selectPicFromCamera() { if (!CommonUtils.isExitsSdcard()) { Toast.makeText(getApplicationContext(), "SD????", 0).show(); return; } cameraFile = new File(PathUtil.getInstance().getImagePath(), com.aidigame.hisun.imengstar.PetApplication.getUserName() + System.currentTimeMillis() + ".jpg"); cameraFile.getParentFile().mkdirs(); startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), REQUEST_CODE_CAMERA); }
From source file:com.example.zf_android.trade.ApplyDetailActivity.java
private void setupItem(LinearLayout item, int itemType, final String key, final String value) { switch (itemType) { case ITEM_EDIT: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); EditText etValue = (EditText) item.findViewById(R.id.apply_detail_value); if (!TextUtils.isEmpty(key)) tvKey.setText(key);// w ww . j av a 2 s .com if (!TextUtils.isEmpty(value)) etValue.setText(value); break; } case ITEM_CHOOSE: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); TextView tvValue = (TextView) item.findViewById(R.id.apply_detail_value); if (!TextUtils.isEmpty(key)) tvKey.setText(key); if (!TextUtils.isEmpty(value)) tvValue.setText(value); break; } case ITEM_UPLOAD: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); final TextView tvValue = (TextView) item.findViewById(R.id.apply_detail_value); if (!TextUtils.isEmpty(key)) tvKey.setText(key); tvValue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { uploadingTextView = tvValue; AlertDialog.Builder builder = new AlertDialog.Builder(ApplyDetailActivity.this); final String[] items = getResources().getStringArray(R.array.apply_detail_upload); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, REQUEST_UPLOAD_IMAGE); break; } case 1: { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File outDir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!outDir.exists()) { outDir.mkdirs(); } File outFile = new File(outDir, System.currentTimeMillis() + ".jpg"); photoPath = outFile.getAbsolutePath(); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile)); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { CommonUtil.toastShort(ApplyDetailActivity.this, getString(R.string.toast_no_sdcard)); } break; } } } }); builder.show(); } }); break; } case ITEM_VIEW: { TextView tvKey = (TextView) item.findViewById(R.id.apply_detail_key); ImageButton ibView = (ImageButton) item.findViewById(R.id.apply_detail_view); if (!TextUtils.isEmpty(key)) tvKey.setText(key); ibView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(ApplyDetailActivity.this, ImageViewer.class); i.putExtra("url", value); i.putExtra("justviewer", true); startActivity(i); } }); } } }