当前位置: 首页>>代码示例>>Java>>正文


Java MediaStore.ACTION_IMAGE_CAPTURE属性代码示例

本文整理汇总了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);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:24,代码来源:PhotoUtils.java

示例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);
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:13,代码来源:PhotoSelector.java

示例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;
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:23,代码来源:MediaLockscreenActivity.java

示例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;
}
 
开发者ID:Sugarya,项目名称:SugarPhotoPicker,代码行数:21,代码来源:ImageCaptureManager.java

示例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);
            }
        }
    }
}
 
开发者ID:sathishmscict,项目名称:Matisse-Image-and-Video-Selector,代码行数:33,代码来源:MediaStoreCompat.java

示例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();
        }
    }
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:16,代码来源:JournalViewActivity.java

示例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);
}
 
开发者ID:jiangkang,项目名称:KTools,代码行数:26,代码来源:ImageActivity.java

示例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();
    }
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:15,代码来源:PSCameraActivity.java

示例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");
    }
 
开发者ID:Andy-Ta,项目名称:COB,代码行数:33,代码来源:CameraLauncher.java

示例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);
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:8,代码来源:MessageAttachmentsFragment.java

示例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;
    }
 
开发者ID:sciage,项目名称:FinalProject,代码行数:29,代码来源:ActivityUtils.java

示例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);
}
 
开发者ID:ChunweiDu,项目名称:Utils,代码行数:10,代码来源:PhotoUtil.java

示例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);
    }
}
 
开发者ID:micromasterandroid,项目名称:androidadvanced,代码行数:7,代码来源:MainActivity.java

示例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);
    }
 
开发者ID:hss01248,项目名称:PhotoOut,代码行数:9,代码来源:MyTool.java

示例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);
}
 
开发者ID:AndroidBoySC,项目名称:Mybilibili,代码行数:11,代码来源:MainActivity.java


注:本文中的android.provider.MediaStore.ACTION_IMAGE_CAPTURE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。