我想发送相机意图拍摄的照片。
当我启动一个Intent时,相机正在显示,但方法postImage不会等到拍照。 PostImage只是在启动意图后加载。
拍照后如何加载postImage?
或
如何检测是否拍摄照片?
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
if(mMediaUri == null){
Toast.makeText(MainActivity.this, "Problem!", Toast.LENGTH_LONG).show();
}
else {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
postImage("mail", mMediaUri.getPath());
}
}
答案 0 :(得分:6)
只需将其用于打开相机:
@api
用于检测捕获(确定或取消按钮)
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
不要忘记给予许可:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
}
}
另请查看以下链接:
http://developer.android.com/training/camera/photobasics.html https://developer.android.com/training/camera/index.html