我剛剛意識到我的相機活動在一個水平方向上不適用於某些設備。一些DROID品牌和皮膚的手機。它適用於迄今爲止所有帶有標準android實現的谷歌手機。安卓相機功能在幾部手機上不起作用
我有一個短暫的瞬間調試設備2.2(不知道到底是什麼型號的手機,這是,但它是皮膚),我看到調試器說(ICamera失敗)(相機錯誤100)
,但我沒有機會找出它出錯的位置,但我確實看到其他人遇到了這個問題(關於在開始預覽前獲取預覽大小的一些信息),但沒有明顯的反應或任何直觀的東西我有,但這裏是我的相機代碼,什麼會使這項工作更普遍?
//this is in OnCreate
preview = (SurfaceView) findViewById(R.id.cameraplacer);
previewHolder = preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
//這是生命週期方法之外
SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
if (camera == null) {
camera = Camera.open();
try {
Camera.Parameters camParams = camera.getParameters();
camParams.setFlashMode(Parameters.FLASH_MODE_AUTO);
setDisplayOrientation(camera, 90);
camera.setPreviewDisplay(previewHolder);
camera.setParameters(camParams);
} catch (IOException e) {
camera.release();
camera = null;
}
}
}//end surfaceCreated
public void surfaceChanged(SurfaceHolder holder,
int format, int width,
int height) {
Camera.Parameters parameters=camera.getParameters();
Camera.Size size=getBestPreviewSize(width, height,
parameters);
if (size!=null) {
parameters.setPreviewSize(size.width, size.height);
camera.setParameters(parameters);
camera.startPreview();
inPreview=true;
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (camera != null) {
camera.stopPreview();
camera.setPreviewCallback(null);
camera.release();
camera = null;
}
}
};//end CallBack
private Camera.Size getBestPreviewSize(int width, int height,
Camera.Parameters parameters) {
Camera.Size result=null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width<=width && size.height<=height) {
if (result==null) {
result=size;
}
else {
int resultArea=result.width*result.height;
int newArea=size.width*size.height;
if (newArea>resultArea) {
result=size;
}
}
}
}
return(result);
}//end getBestPreviewSize
//這是對的onResume
try {
//Method rotateMethod = android.hardware.Camera.class.getMethod("setDisplayOrientation", int.class);
//rotateMethod.invoke(camera, 90);
//Camera.Parameters camParams = camera.getParameters();
//camParams.setPreviewSize(480, 320);// here w h are reversed
//camera.setParameters(camParams);*/
//setCameraDisplayOrientation(MainPhoto.this, 0, camera);
if(camera!=null)
{
Camera.Parameters camParams = camera.getParameters();
camParams.setFlashMode(Parameters.FLASH_MODE_AUTO);
camera.setParameters(camParams);
setDisplayOrientation(camera, 90);
camera.setPreviewDisplay(previewHolder);
camera.startPreview();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/* catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/ catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/* catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
沒有日誌和控制檯消息,你會得到,我不認爲很多人都可以幫助你。 – 2012-01-05 22:21:47