まず最初に:次のエラーは、2つの異なるHTC Desiresで発生します。1つは2.3.3で、もう1つは4.0.4です。
.takePictureを呼び出そうとすると、次のエラーメッセージが表示されます。
E/MemoryHeapBase(104): error opening /dev/pmem_camera: No such file or directory
E/QualcommCameraHardware(104): failed to construct master heap for pmem pool /dev/pmem_camera
E/QualcommCameraHardware(104): initSnapshot X failed with pmem_camera, trying with pmem_adsp
このエラーの後、対応するPictureCallbackが呼び出されることはありません。
私が見つけた唯一の説明は次のとおりでした。a)startPreviewが呼び出されなかった。b)写真の撮影が速すぎる(写真のコールバックが呼び出される前)。c)正しい使用/許可を設定していない
私はa)ここで、FullscreenActivityのonResume()で次のことを行います。
//open the camera resource
cam = Camera.open();
Camera.Parameters params = cam.getParameters();
//change Parameters
params.setJpegQuality(100);//best quality
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
//params.setZoom(2);
List<Size> supportedPreviewSizes = cam.getParameters().getSupportedPreviewSizes();
params.setPreviewSize(supportedPreviewSizes.get(0).width, supportedPreviewSizes.get(0).height);
cam.setParameters(params);
SurfaceView sv = (SurfaceView)this.findViewById(R.id.surfaceView1);
SurfaceHolder mHolder = sv.getHolder();
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mHolder.setSizeFromLayout();
mHolder.addCallback(this);
try {
cam.setPreviewDisplay(mHolder);
} catch (IOException e) {
Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}
//Log.d(TAG, "Starting Preview");
cam.startPreview();
b)私は一枚の写真しか撮ろうとしないので、私には当てはまらないはずです
c):使用-私のマニフェストの一部:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera.flash"/>
いくつかの追加コード:
takePictureを呼び出す場合(ここに記録すると、AsyncTaskは完了後にtakePictureを再度呼び出すことができます。ただし、AsyncTaskを呼び出さなくてもエラーが続くため、関係ありません):
findViewById(R.id.snap_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recording = !recording;
Button btn = (Button)findViewById(R.id.snap_button);
if(recording) {
//update buttontext
btn.setText("Stop");
//start recording by taking a picture
cam.takePicture(null,null, mPicture);
} else {
//update button text
btn.setText("Start");
}
}
});
編集: レイアウトを少し変更した後、pictureCallbackが最終的に呼び出され、有効なデータを取得します(yay)が、エラーは解決しません。これが私の現在のレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="0dp"
android:layout_height="369dp"
android:layout_weight="1.55" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/snap_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>