title: Where in the code set camera parameters?
body: <p>I'm using this to use android camera:</p>
  
  <p>public class Login extends Activity implements SurfaceHolder.Callback {</p>
  
  <pre><code>public int idCamera(int id) {
      if (id == 0) { id = 1; } else { id = 0; }
      int tcam = Camera.getNumberOfCameras();
      if (tcam == 1) { id = 0; }
      return id;
  }
  
  public class idCameraV {
      public int id;
  }
  
  public static class camHolder {
      public static SurfaceHolder id;
  }
  
  private Camera camera;
  private SurfaceView surfaceView;
  
  static String senha2;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.login);
  
      final idCameraV idCam = new idCameraV();
      idCam.id = 0;
  
      camera = Camera.open(idCam.id);
      Camera.Parameters parametro = camera.getParameters(); // WORKS OK
      parametro.setFlashMode("on"); // WORKS OK
      camera.setParameters(parametro); // WORKS OK
  
      surfaceView = (SurfaceView) findViewById(R.id.preview);
      surfaceView.getHolder().addCallback(this);
  
      final ImageButton button1 = (ImageButton) findViewById(R.id.bt_camera);
      button1.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              camera.stopPreview();
              camera.release();
              idCam.id = idCamera(idCam.id);
              camera = Camera.open(idCam.id); 
              Camera.Parameters parametro = camera.getParameters();
              parametro.setFlashMode("on"); // THIS LINE AND ABOVE WORKS. I CAN READ BY GETFLASHMODE
              camera.setParameters(parametro); // ERROR IN HERE
              camera.startPreview();
                  try {
              camera.setPreviewDisplay(camHolder.id);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      });
  
      final ImageButton button2 = (ImageButton) findViewById(R.id.bt_login);
      button2.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {                
              EditText senha = (EditText)findViewById(R.id.senha);
              senha2 = senha.getText().toString();                
              ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
              RelativeLayout aviso = (RelativeLayout) findViewById(R.id.aguarde);
              aviso.setVisibility(View.VISIBLE);              
              LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
              String coordenadas = GPS.coordenadas(locationManager);
              String android_id = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID);
              camera.takePicture(null, null, new TiraFoto(getApplicationContext(), android_id, coordenadas, aviso, connMgr, "LOGIN_", camera));
          }
      });
  
  }
  
  @Override
  protected void onDestroy() {
      super.onDestroy();
      if (camera != null) { camera.release(); }
  }
  
  @Override
  protected void onPause() {
      super.onPause();
      if (camera != null) { camera.stopPreview(); }
  }
  
  @SuppressWarnings("static-access")
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
      try {
          camera.setPreviewDisplay(holder);
          camera.startPreview();
          final camHolder camHolderId = new camHolder();
          camHolderId.id = holder;
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
      if (holder.getSurface() != null) {
          try {
              camera.stopPreview();
          } catch (Exception e) {
      }
          try {
              camera.setPreviewDisplay(holder);
              camera.startPreview();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {}
  </code></pre>
  
  <p>}</p>
  
  <p>It works ok, but when I do the camera swap, the app freezes. I'm setting the flashmode when I open the camera first time, and it works, but when I do the swap, I get a set parameter error. Where I must set this parameters?</p>