-1
if(camera == null){

Toast.makeText(getBaseContext(),"without camera",Toast.LENGTH_LONG).show(); 


return;
  }

-------------------------------------------------------------------------------------------- add full code

button.setOnClickListener(new OnClickListener() {


   public void onClick(View v) {




    if (isLightOn) {

     p.setFlashMode(Parameters.FLASH_MODE_OFF);

     camera.setParameters(p);
     camera.stopPreview();
     isLightOn = false;
     Toast.makeText(context, R.string.off, Toast.LENGTH_SHORT).show();

    } else {


     p.setFlashMode(Parameters.FLASH_MODE_TORCH);

     camera.setParameters(p);
     camera.startPreview();
     isLightOn = true;
     Toast.makeText(context, R.string.on, Toast.LENGTH_SHORT).show();
    }


   }
  });

Sorry for my Eng.

How do I make that when you click on the button to check for flash the phone? And when no flash - display a message (Toast)

GROM
  • 1
  • 1
  • Check out [this question](http://stackoverflow.com/questions/6068803/how-turn-on-only-camera-flash-light-programmatically-in-android) – Andrey Ermakov May 21 '12 at 15:32

1 Answers1

0

make a button object

add an onclicklistener

within the onclicklistener's onClick function, add your logic there.

CQM
  • 42,592
  • 75
  • 224
  • 366