gpt4 book ai didi

android - 打开 Galaxy Nexus 手电筒

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:51:19 25 4
gpt4 key购买 nike

我正在开发一个需要打开我的 Galaxy Nexus 设备手电筒的应用程序。我在这里提到了帖子

LED flashlight on Galaxy Nexus controllable by what API?

public class TestCamera extends Activity implements SurfaceHolder.Callback{
Camera mCamera;
public static SurfaceView preview;
public static SurfaceHolder mHolder;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
preview = (SurfaceView) findViewById(R.id.camSurface);
mHolder = preview.getHolder();
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(mHolder);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Button onLEDbtn = (Button) findViewById(R.id.onLED_btn);
onLEDbtn.setOnClickListener(new OnClickListener(){

public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);
mCamera.startPreview();
}

});
}



}


public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub

}


public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
mHolder = holder;
try {
mCamera.setPreviewDisplay(mHolder);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
mCamera.stopPreview();
mHolder = null;
}




}

list :

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

但是,我还是打不开手电筒。谁能指出我的错误?谢谢

最佳答案

你必须设置回调mHolder.addCallback(this);

关于android - 打开 Galaxy Nexus 手电筒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10734858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com