2012-05-24 13 views
8

Sto sviluppando un'applicazione che deve aprire la torcia del mio dispositivo Galaxy Nexus. Ho fatto riferimento al post quiApertura della torcia del 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; 
    } 




} 

manifesto:

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

Tuttavia, ho interruttore ancora cant sulla torcia. Qualcuno potrebbe indicare i miei errori? Grazie

+0

è possibile trovare tutto qui http://stackoverflow.com/questions/6068803/how-turn-on-only-camera-flash-light-programmatically-in-android – user219882

+0

possibile duplicato di [Impossibile utilizzare la torcia in Galaxy Nexus] (http://stackoverflow.com/questions/10731285/unable-to-use-the-flashlight-in-galaxy-nexus) –

+0

Sopra è il mio file manifest Inoltre, ho aggiunto la vista camSurface all'interno di main.xml Sarà un problema? Posso ottenere il messaggio di pane tostato ma non posso accendere la torcia ... Per favore aiuto. Grazie!! – user1311794

risposta

0

tenta di aggiungere:

android:name="android.permission.FLASHLIGHT" 
android:name="android.hardware.camera.flash 

E guarda questo post: How to turn on camera flash light programmatically in Android?

+0

Ho il seguente manifesto Tuttavia non funziona. – user1311794

+0

ho trovato questo post: http://stackoverflow.com/questions/9505945/led-flashlight-does-not-work-on-samsung-galaxy-nexus – Skies

+0

e questo: http: // stackoverflow. it/questions/8876843/led-flashlight-on-galaxy-nexus-controllable-by-what-api/9379765 # 9379765 – Skies

0

È necessario aggiungere questo tag nel file manifesto.

<uses-feature android:name="android.hardware.camera.flash"/> 
7

è necessario impostare richiamare mHolder.addCallback (questo);

Problemi correlati