Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use camera flash/led as torch on a Samsung Galaxy Tab?
    text
    copied!<p>I'm facing to a problem with a Samsung Galaxy Tab. I want to use the camera flash as torch.</p> <p>Does anyone know how to enable it ?</p> <p>Hereby a code that works to enable/disable the camera flash on a HTC Desire but fails on Samsung Galaxy Tab.</p> <p><em><strong>FlashLight.java :</em></strong></p> <pre><code>package com.example.FlashLight; import android.app.Activity; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class FlashLight extends Activity { private final static String LOG_TAG = "FlashLight"; private Button mOnBtn; private Button mOffBtn; private Camera mCamera; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mOnBtn = (Button) findViewById(R.id.on_btn); mOnBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processOnClick(); } }); mOffBtn = (Button) findViewById(R.id.off_btn); mOffBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processOffClick(); } }); } @Override protected void onResume() { super.onResume(); try{ mCamera = Camera.open(); } catch( Exception e ){ Log.e(LOG_TAG, "Impossible d'ouvrir la camera"); } } @Override protected void onPause() { if( mCamera != null ){ mCamera.release(); mCamera = null; } super.onPause(); } private void processOffClick(){ if( mCamera != null ){ Parameters params = mCamera.getParameters(); params.setFlashMode( Parameters.FLASH_MODE_OFF ); mCamera.setParameters( params ); } } private void processOnClick(){ if( mCamera != null ){ Parameters params = mCamera.getParameters(); params.setFlashMode( Parameters.FLASH_MODE_TORCH ); mCamera.setParameters( params ); } } } </code></pre> <p><em><strong>AndroidManifest.xml :</em></strong> </p> <pre><code> &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".FlashLight" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;uses-permission android:name="android.permission.CAMERA" /&gt; &lt;uses-feature android:name="android.hardware.camera" /&gt; &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt; &lt;/manifest&gt; </code></pre> <p><em><strong>layout/main.xml :</em></strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Button android:id="@+id/on_btn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Flash ON" /&gt; &lt;Button android:id="@+id/off_btn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Flash OFF" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Thanks !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload