1、打开系统相机
protected File cameraFile;
protected void selectPicFromCamera() {
if (!EaseCommonUtils.isExitsSdcard()) {
Toast.makeText(getActivity(), R.string.sd_card_does_not_exist, Toast.LENGTH_SHORT).show();
return;
}
cameraFile = new File(PathUtil.getInstance().getImagePath(), EMChatManager.getInstance().getCurrentUser()
+ System.currentTimeMillis() + ".jpg");
cameraFile.getParentFile().mkdirs();
startActivityForResult(
new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)),
REQUEST_CODE_CAMERA);
}
2、处理返回结果
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUEST_CODE_CAMERA) { // 发送照片
if (cameraFile != null && cameraFile.exists())
//TODO you hava a file......sendImageMessage(cameraFile.getAbsolutePath());
}
}
}