次のコードは、カメラから写真を撮り、次のアクティビティに画像を設定するのに役立ちます
private void takePicture() {
cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, IMAGE_CAPTURE);
}
// Receive the result from the start Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e("onActivityResult", "we r in onActivityResult");
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case IMAGE_CAPTURE:
File dir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(dir, "camerascript.png");
cPath = output.getAbsolutePath();
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(output));
Intent capIntent = new Intent(yourcurrentActivity.this,
yournextActivity.class);
capIntent.putExtra("gallery", cPath);
startActivity(capIntent);
break;
default:
break;
}
}
}
その後yournextAactivity
、キャプチャした画像を設定したい場所に intnet の余分なデータを取得します。
ImageView imageView = (ImageView)findViewById(R.id.imgView);
String fileString = getIntent().getStringExtra("gallery");
imageView.setImageBitmap(BitmapFactory.decodeFile(fileString));