1. Download our Official Android App: Forums for Android!

Apps how to start camera flash

Discussion in 'Android Development' started by Ghzsoft, Jul 18, 2011.

  1. Ghzsoft

    Ghzsoft Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 11, 2011

    Jun 11, 2011
    5
    0
    5
    Hi guys I tried to start the camera flash for an app I'm doing but I don't understand why it isn't working. What did I do wrong?
    here is the code:

    Code (Text):
    1.  
    2. import android.app.Activity;
    3. import android.hardware.Camera;
    4. import android.hardware.Camera.Parameters;
    5. import android.os.Bundle;
    6. import android.view.View;
    7. import android.view.View.OnClickListener;
    8. import android.widget.Button;
    9.  
    10. public class CameraTest extends Activity {
    11.    
    12.     private Button btnOn;
    13.     private Button btnOff;
    14.    
    15.     private Camera mCamera;
    16.    
    17.     @Override
    18.     public void onCreate(Bundle savedInstanceState) {
    19.         super.onCreate(savedInstanceState);
    20.         setContentView(R.layout.main);
    21.        
    22.         btnOn = (Button)findViewById(R.id.lightOn);
    23.         btnOn.setOnClickListener(new OnClickListener(){
    24.  
    25.             @Override
    26.             public void onClick(View v) {
    27.                 startLight();
    28.             }
    29.  
    30.         });
    31.        
    32.         btnOff = (Button)findViewById(R.id.lightOff);
    33.         btnOff.setOnClickListener(new OnClickListener(){
    34.  
    35.             @Override
    36.             public void onClick(View v) {
    37.                 stopLight();
    38.             }
    39.            
    40.         });
    41.     }
    42.    
    43.     @Override
    44.     protected void onResume(){
    45.         super.onResume();
    46.         mCamera = Camera.open();
    47.     }
    48.    
    49.     @Override
    50.     protected void onPause() {
    51.         if( mCamera != null ){
    52.             mCamera.release();
    53.             mCamera = null;
    54.         }
    55.         super.onPause();
    56.     }
    57.    
    58.    
    59.    
    60.     private void startLight() {
    61.        
    62.         if(mCamera!=null){
    63.             Parameters mCameraParameters = mCamera.getParameters();
    64.             mCameraParameters.setFlashMode( Parameters.FLASH_MODE_TORCH);
    65.             mCamera.setParameters(mCameraParameters);
    66.             mCamera.startPreview();
    67.         }
    68.     }
    69.    
    70.     private void stopLight() {
    71.         if(mCamera!=null){
    72.             Parameters mCameraParameters = mCamera.getParameters();
    73.             mCameraParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
    74.             mCamera.setParameters(mCameraParameters);
    75.             mCamera.stopPreview();
    76.         }
    77.     }
    78.    
    79.    
    80. }
    81.  
    Anyone can help me?

    For information I'm using a LG Optimus 3D for the test of this app.

    Thanks
     

    Advertisement

  2. Ghzsoft

    Ghzsoft Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jun 11, 2011

    Jun 11, 2011
    5
    0
    5
    No one can help me?? :(
     
  3. larsdiego

    larsdiego Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Nov 24, 2011

    Nov 24, 2011
    1
    0
    5
    Hi,
    I'm facing the same issues with a HTC...
    Did you get further on this issue?
    Thanks!
    Cheers
     

Share This Page

Loading...