Android API21(5.0)及以后无需权限拍照和选择图片
2020-03-31 本文已影响0人
小强开学前
1. 调用系统相机拍照
if(requiredActivity().packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
requiredActivity().startActivityForResult(intent, Constants.PHOTO_FROM_CAMERA)
}else
Util.toast(R.string.no_camera)
2. 调用系统图库选择
val intent = Intent(Intent.ACTION_PICK)
intent.type = "image/*"
requiredActivity().startActivityForResult(intent, Constants.PHOTO_FROM_GALLERY)
另外启动的ACTION也可以使用Intent.ACTION_GET_CONTENT