Unable to use the flashlight in Galaxy Nexus

给你一囗甜甜゛ 提交于 2019-12-20 00:49:20

问题


I have to following code and I just want to open the flashlight in my Galaxy Nexus(4.0.2) and it failed to do so.

public class welcome extends Activity {

//MediaPlayer player;
/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome);

    Camera cam = Camera.open();     
    Parameters p = cam.getParameters();
    p.setFlashMode(Parameters.FLASH_MODE_TORCH);
    cam.setParameters(p);
    cam.startPreview();



}
}

My Manifest file:

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

I would like to ask if it is my coding error or android version problem? Thanks


回答1:


The galaxy nexus is unable to use the flash without having an attached surfaceView and surfaceHolder. I have a Nexus myself, and after attaching the preview-view it worked. Since you dont want to see what the camera sees in a flashlight app, just make it 1x1 pixel.

Source: LED Flashlight does not work on Samsung Galaxy Nexus




回答2:


Have you tried the code here: http://android-er.blogspot.co.uk/2011/02/control-flash-light-function-as-torch.html

It definitely works on a rooted Desire running Cyanogenmod 7 and on an ICS rom (4.0.3) for me. Perhaps try running this and see if it works, and then proceed from there?

It also includes checks to see if it can find the camera, then open the camera. There seems to be no need for the StartPreview().

The order of events seems different:

1: If camera is present, open camera 2: Set parameters 3: parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
4: camera.setParameters(parameters);




回答3:


Use surface view to attach camera as some of the devices needs surface view. I am sure this will work a link! for you



来源:https://stackoverflow.com/questions/10731285/unable-to-use-the-flashlight-in-galaxy-nexus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!