android 调用系统相机拍照获取照片时,为什么先跳到桌面,然后再回到调用相机的Activity

2025-01-01 00:46:36
推荐回答(2个)
回答1:

public static String getCapturePath(Activity activity) {
String path = getImageSavePath() + "/" + getTime("yyyyMMddHHmmss")
+ ".jpg";
Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraintent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File(path)));
activity.startActivityForResult(cameraintent,
Constants.CAMERA_REQUEST_CODE);
return path;
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == Constants.CAMERA_REQUEST_CODE)
{
CameraManager.intance().compresImage();
return;
}
}
compresImage();这个方法是压缩图片
public void compresImage()
{
if (!new File(cameraPath).isFile()) {
return;
}
compresPath = AppTools.getImageCompresPath();
// 对图片进行压缩

ImageDispose.compressImage(cameraPath, compresPath, 450);
Bitmap bm = ImageDispose.rotate(BitmapFactory.decodeFile(compresPath));
if(view.getVisibility() == View.GONE){
view.setVisibility(View.VISIBLE);
}
view.setImageBitmap(bm);
view.invalidate();
view.setTag(compresPath);
}

回答2:

startActivityForResult(); 在重新onResult方法。