在棒棒糖中使用相机捕获图像时出现问题

Issue in capture image using camera in lollipop

下面这个问题我找了三天了

我的代码如下

private void openCamera () {    
    try {
        Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        String fileName = Constants.IMAGE_CAPTURE_FILE_NAME_PREFIX + System.currentTimeMillis() + Constants.IMAGE_FILE_EXT_JPG;
        mImageFile = new File(FileManager.getInstance().getFileFullName(Constants.IMAGE_FOLDER, fileName));
        captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageFile);
        startActivityForResult(captureIntent, Constants.ACTIVITY_CAMERA_REQUEST_CODE);     
    } catch(ActivityNotFoundException anfe) {   
        String errorMessage = "Whoops - your device doesn't support capturing images!";
        Toast toast = Toast.makeText(ImagesSelectorActivity.this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}



public String getFileFullName(String folderName, String fileName) {
    String filepath;
    if (PhoneUtils.isSDCardFound() == true)
        filepath = Environment.getExternalStorageDirectory().getPath();
    else
        filepath = Environment.getDataDirectory().getPath();

    File file = new File(filepath, folderName);

    if (!file.exists()) {
        file.mkdirs();
    }

    return (file.getAbsolutePath() + "/" + fileName);
}

Activity 个结果

if(requestCode == Constants.ACTIVITY_CAMERA_REQUEST_CODE) {

    Uri picUri = data.getData();

    if (picUri == null) {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        Uri tempUri = PhoneUtils.getBitmapUri(getApplicationContext(), bitmap);
        Log.i("AMIRA", tempUri.toString());

    }

    performPreview(picUri);
}

图片没有保存在我的文件夹中,return是缩略图uri的url问题

我需要在拍摄后将图像保存在我需要的路径中,以便能够读取完整尺寸的图像。

我在设备的任何地方都找不到从相机拍摄的图像。

Class文件如下:

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MyCameraActivity extends Activity {
private static final int CAMERA_REQUEST = 1888; 
private ImageView imageView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult(cameraIntent, CAMERA_REQUEST); 
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);
    }  
} 

}

XML 文件:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >

 <Button android:id="@+id/button1" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Take Picture">
 </Button>

<ImageView 
android:id="@+id/imageView1"   
android:layout_height="wrap_content" 
android:src="@drawable/ic_launcher" 
android:layout_width="wrap_content">
</ImageView>

在清单文件中添加权限:

<uses-feature android:name="android.hardware.camera"></uses-feature> 

希望这对您有所帮助...

我使用的过程与您的几乎相同,效果很好。请尝试执行以下操作:

在打开相机部分,不是发送File而是发送Uri,像这样:

mImageUri = Uri.fromFile(mImageFile); //keep mImageUri as member so that you can use it on the activity result.
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);  

然后在 onActivityResult 中执行此操作:

if (mImageUri != null && !mImageUri.getPath().isEmpty()) {
    performPreview(mImageUri);
}

希望对您有所帮助!