Question

I have been looking everywhere on how to turn my Nexus One LED On/Off from a button that I created. I can't get it to work. I get a "threadid=1 thread exiting with uncaught exception (group=0x40015560)" error and I am stuck. Can anyone help me out? Here is my code.

//Here are class declarations
Camera mCamera;
Camera.Parameters mParameters;
boolean mbTorchEnabled = false;

//This one is inside my OnClickListener
if(v.getId() == R.id.button1){

    mParameters = mCamera.getParameters();
    if(mbTorchEnabled){
        mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    }else{
    mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    }
    mCamera.setParameters(mParameters);
    mbTorchEnabled = !mbTorchEnabled;
}
Was it helpful?

Solution

I figured it out! Turns out my code is correct for this. I just needed permissions. So going into the Android Manifest file, I added these lines:

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

Link to where I found it was: http://developer.android.com/reference/android/hardware/Camera.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top