Android打开系统相机 适配Android7.0

来源:互联网 发布:崩坏3矩阵buff表 编辑:程序博客网 时间:2024/05/22 06:15
    /**     * 调用系统相机     */    public String openCamera(int requestCode) {        String cameraPath = Environment.getExternalStorageDirectory().getPath() + "/" + context.getPackageName() + "/camera/";        //调用系统自带相机        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);        File file = new File(cameraPath);        if (!file.exists()) {            file.mkdirs();        }        //拍摄照片时的毫秒值(用来当做图片的名称)        long time = System.currentTimeMillis();        File path = new File(cameraPath, time + ".png");        ContentValues contentValues = new ContentValues(1);        contentValues.put(MediaStore.Images.Media.DATA, path.getAbsolutePath());        Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);        startActivityForResult(intent, requestCode);        return path.getPath();    }

阅读全文
1 0
原创粉丝点击