我试图弄清楚在使用相机意图时如何从相机获取图像。
当尝试捕获图像时,照片应用程序或相机活动仍然存在,它不会返回到我应该显示捕获的照片的其他应用程序。
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,相机意图活动出现,我可以拍照、保存、删除,做我的相机所做的所有事情。问题是,当我使用相机活动保存或拍照时,它不会回到我原来的应用程序,或者如果我点击手机上的后退按钮,它不会显示?
先感谢您!