**从图库获取图片**
public void selectPicFromLocal() {
Intent intent;
if (Build.VERSION.SDK_INT < 19) {
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
} else {
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
startActivityForResult(intent, REQUEST_CODE_LOCAL);
}
**照相获取图片**
public void selectPicFromCamera() {
if (!CommonUtils.isExitsSdcard()) {
String st = getResources().getString(R.string.sd_card_does_not_exist);
Toast.makeText(getApplicationContext(), st, 0).show();
return;
}
cameraFile = new File(PathUtil.getInstance().getImagePath(), LexueApplication.getInstance().getCurrentUserInfo(LexueBackendHelper.IM_USER_NAME)
+ System.currentTimeMillis() + ".jpg");
cameraFile.getParentFile().mkdirs();
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)),
REQUEST_CODE_CAMERA);
}
Android从相册获取图片,拍照获取图片
最新推荐文章于 2021-04-12 15:20:21 发布