android 相册 相机 获取相片 相册 2中方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013148839/article/details/53259704
  // 相册选取
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                startActivityForResult(intent, Constants.REQUEST_CODE_GALLERY);

                // 相册选取
                Intent intent = new Intent(
                        Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, Constants.REQUEST_CODE_GALLERY);


  // 拍照
                        File temp = new File(PicUtils.PATH);
                        Uri imageFileUri = Uri.fromFile(temp);//获取文件的Uri
                        Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//跳转到相机Activity
                        it.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);//告诉相机拍摄完毕输出图片到指定的Uri
                        startActivityForResult(it, Constants.REQUEST_CODE_PHOTOGRAPH);

猜你喜欢

转载自blog.csdn.net/u013148839/article/details/53259704