简体   繁体   English

无法在Galaxy Nexus中使用手电筒

[英]Unable to use the flashlight in Galaxy Nexus

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. 我必须遵循代码,我只是想在我的Galaxy Nexus(4.0.2)中打开手电筒,但它没有这样做。

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? 我想问一下,这是我的编码错误还是android版本问题? Thanks 谢谢

The galaxy nexus is unable to use the flash without having an attached surfaceView and surfaceHolder. 没有附加的surfaceView和surfaceHolder,galaxy nexus无法使用闪光灯。 I have a Nexus myself, and after attaching the preview-view it worked. 我自己有一个Nexus,在附加了预览视图之后就可以了。 Since you dont want to see what the camera sees in a flashlight app, just make it 1x1 pixel. 由于您不想看到相机在手电筒应用中看到的内容,只需将其设为1x1像素即可。

Source: LED Flashlight does not work on Samsung Galaxy Nexus 消息来源: LED手电筒不适用于三星Galaxy Nexus

Have you tried the code here: http://android-er.blogspot.co.uk/2011/02/control-flash-light-function-as-torch.html 您是否尝试过此处的代码: 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. 它肯定适用于运行Cyanogenmod 7的根管Desire和我的ICS ROM(4.0.3)。 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(). 似乎没有必要使用StartPreview()。

The order of events seems different: 事件的顺序似乎不同:

1: If camera is present, open camera 2: Set parameters 3: parameters.setFlashMode(Parameters.FLASH_MODE_TORCH); 1:如果摄像机存在,则打开摄像机2:设置参数3:parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
4: camera.setParameters(parameters); 4:camera.setParameters(参数);

Use surface view to attach camera as some of the devices needs surface view. 使用表面视图连接相机,因为某些设备需要表面视图。 I am sure this will work a link ! 我相信这会工作的链接 for you 为了你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM