本文整理汇总了Java中android.provider.MediaStore.ACTION_IMAGE_CAPTURE属性的典型用法代码示例。如果您正苦于以下问题:Java MediaStore.ACTION_IMAGE_CAPTURE属性的具体用法?Java MediaStore.ACTION_IMAGE_CAPTURE怎么用?Java MediaStore.ACTION_IMAGE_CAPTURE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.provider.MediaStore
的用法示例。
在下文中一共展示了MediaStore.ACTION_IMAGE_CAPTURE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openCamera
/**
* 打开系统相机
* @param context
* @param fileName
*/
public static void openCamera(Context context, String fileName) {
String status = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED.equals(status)) {
Toast.makeText(context, "SD卡不可以", Toast.LENGTH_LONG).show();
return;
}
File mCurrentPhotoFile = new File(context.getExternalCacheDir(), fileName);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri imageUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // 7.0使用FileProvider
imageUri = FileProvider.getUriForFile(context, "com.highway.study.provider", mCurrentPhotoFile);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
imageUri = Uri.fromFile(mCurrentPhotoFile);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, MAX_PHOTO_SIZE);
((Activity)context).startActivityForResult(intent, CAMERA_WITH_DATA);
}
示例2: requestSysCamera
/**
* Fragment调用系统拍照
*
* @param fragment
* @param requestCode
*/
public void requestSysCamera(android.support.v4.app.Fragment fragment, int requestCode) {
requestCamaraPath = getPhotoTmpPath();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(requestCamaraPath)));
fragment.startActivityForResult(intent, requestCode);
}
示例3: onLongClick
@Override
public boolean onLongClick(View arg0) {
//
if (mSettings.getBoolean("use_as_lock_main", false)) {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
Intent i = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
PackageManager pm = getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Intent intent = new Intent();
intent.setComponent(new ComponentName(
mInfo.activityInfo.packageName, mInfo.activityInfo.name));
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
return true;
}
示例4: dispatchTakePictureIntent
public Intent dispatchTakePictureIntent() throws IOException {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = createImageFile();
// Continue only if the File was successfully created
if (photoFile != null) {
Uri uri = null;
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(mContext.getApplicationContext(), mContext.getPackageName() + ".file_provider", photoFile);
} else {
uri = Uri.fromFile(photoFile);
}
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
takePictureIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);//增加读写权限
}
}
return takePictureIntent;
}
示例5: dispatchCaptureIntent
public void dispatchCaptureIntent(Context context, int requestCode) {
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (captureIntent.resolveActivity(context.getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
if (photoFile != null) {
mCurrentPhotoPath = photoFile.getAbsolutePath();
mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(),
mCaptureStrategy.authority, photoFile);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri);
captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
List<ResolveInfo> resInfoList = context.getPackageManager()
.queryIntentActivities(captureIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, mCurrentPhotoUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
if (mFragment != null) {
mFragment.get().startActivityForResult(captureIntent, requestCode);
} else {
mContext.get().startActivityForResult(captureIntent, requestCode);
}
}
}
}
示例6: do_add_photo
@OnClick(R.id.fab_add_photo)
public void do_add_photo()
{
Intent capture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (capture.resolveActivity(getPackageManager()) != null) {
try {
File photoFile = createFileName("traxypic", ".jpg");
mediaUri = FileProvider.getUriForFile(this,
getPackageName() + ".provider", photoFile);
capture.putExtra(MediaStore.EXTRA_OUTPUT, mediaUri);
startActivityForResult(capture, CAPTURE_PHOTO_REQUEST);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例7: openCameraWithOutput
private void openCameraWithOutput() {
String path = new File(Environment.getExternalStorageDirectory(), "ktools").getAbsolutePath();
if (!new File(path).exists()) {
new File(path).mkdirs();
}
outputImageFile = new File(path, System.currentTimeMillis() + ".png");
if (!outputImageFile.exists()) {
try {
outputImageFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
//兼容7.0
Uri contentUri = FileProvider.getUriForFile(
this,
BuildConfig.APPLICATION_ID,
outputImageFile
);
Log.d(TAG, "openCameraWithOutput: uri = " + contentUri.toString());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(Intent.EXTRA_MIME_TYPES, MimeTypeMap.getSingleton().getMimeTypeFromExtension("png"));
//指定输出路径
intent.putExtra(MediaStore.EXTRA_OUTPUT, contentUri);
startActivityForResult(intent, REQUEST_CODE_CAPTURE_IMAGE_WITHOUT_COMPRESS);
}
示例8: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (cameraResultListener != null && cameraResultListener.getFilePath() != null) {
File tempImageFile = new File(cameraResultListener.getFilePath());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri uri = PSFileProvider.getUriForFile(this, PSFileProvider.getProviderName(this), tempImageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
this.startActivityForResult(intent, REQUEST_CODE);
} else {
Intent result = new Intent();
setResult(Activity.RESULT_CANCELED, result);
finish();
}
}
示例9: takePicture
public void takePicture(int returnType, int encodingType)
{
// Save the number of images currently on disk for later
this.numPics = queryImgDB(whichContentStore()).getCount();
// Let's use the intent and see what happens
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Specify file so that large image is captured and returned
File photo = createCaptureFile(encodingType);
this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
applicationId + ".provider",
photo));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri.getCorrectUri());
//We can write to this URI, this will hopefully allow us to write files to get to the next step
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (this.cordova != null) {
// Let's check to make sure the camera is actually installed. (Legacy Nexus 7 code)
PackageManager mPm = this.cordova.getActivity().getPackageManager();
if(intent.resolveActivity(mPm) != null)
{
this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
}
else
{
LOG.d(LOG_TAG, "Error: You don't have a default camera. Your device may not be CTS complaint.");
}
}
// else
// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}
示例10: startCamera
@Override
public void startCamera(@NonNull Uri fileUri) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(takePictureIntent, REQUEST_PHOTO_FROM_CAMERA);
}
}
示例11: openCamera
public static Uri openCamera(Activity activity) {
if (isStoragePermissionGranted(activity,
activity.getResources().getInteger(R.integer.camera_request))) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri photoURI;
ContentValues values = new ContentValues(1);
values.put(MediaStore.Images.Media.MIME_TYPE, "profile_image/jpg");
photoURI = activity.getContentResolver()
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
intent.addFlags(
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
if (photoURI != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
}
activity.startActivityForResult(intent,
activity.getResources().getInteger(R.integer.camera_request));
return photoURI;
}
return null;
}
示例12: openCameraImage
public static void openCameraImage(final Fragment fragment) {
imageUriFromCamera = createImagePathUri(fragment.getContext());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// MediaStore.EXTRA_OUTPUT参数不设置时,系统会自动生成一个uri,但是只会返回一个缩略图
// 返回图片在onActivityResult中通过以下代码获取
// Bitmap bitmap = (Bitmap) data.getExtras().get("data");
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUriFromCamera);
fragment.startActivityForResult(intent, GET_IMAGE_BY_CAMERA);
}
示例13: dispatchTakePictureIntent
@OnClick(R.id.button)
public void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
示例14: startCamera
public static void startCamera(Activity activity,BasePhotoBuilder builder){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
Uri mDestinationUri = buildUri(builder,true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mDestinationUri);
activity.startActivityForResult(intent, PhotoUtil.REQUEST_CAMERA);
}
示例15: choseHeadImageFromCameraCapture
/**
* 从手机相机拍摄图片设置用户头像
*/
private void choseHeadImageFromCameraCapture() {
Intent intentFromCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//判断存储卡是否可用,存储照片文件
if(hasSdcard()){
intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(Environment.getExternalStorageDirectory(),IMAGE_FILE_NAME)));
}
startActivityForResult(intentFromCapture,CODE_CAMERA_REQUEST);
}