我正在试图弄清楚如何在使用相机意图时从相机获取图像。
当尝试捕捉图像时,照片应用程序或相机活动仍然存在,它不会返回我的其他应用程序,其中应该显示捕获的照片。
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.photo_camera_button:
Intent photoIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(photoIntent, CAMERA_PHOTO_REQUEST);
break;
case R.id.video_camera_button:
Intent videoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(videoIntent, CAMERA_VIDEO_REQUEST);
break;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
if(requestCode == CAMERA_PHOTO_REQUEST){
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
ImageView imv = (ImageView) findViewById(R.id.ReturnedImageView);
imv.setImageBitmap(bmp);
//HttpGetMethod client = new HttpGetMethod();
}
if(requestCode == CAMERA_VIDEO_REQUEST){
Context context1 = getApplicationContext();
CharSequence text1 = "Video!";
int duration1 = Toast.LENGTH_LONG;
Toast toast1 = Toast.makeText(context1, text1, duration1);
toast1.show();
}
}
}
在我的xml中,我有ImageView
<ImageView
android:id="@+id/ReturnedImageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/ic_launcher" />
用户点击photo_camera_button,相机意图活动显示,我可以拍照,保存,删除,做我相机所做的所有事情。问题是,当我使用相机活动保存或拍照时,它不会返回原来的应用程序,或者如果我点击手机上的后退按钮,它就不显示了?
提前谢谢!