LED手电筒Galaxy Nexus的控制由什么API? [英] LED flashlight on Galaxy Nexus controllable by what API?

查看:189
本文介绍了LED手电筒Galaxy Nexus的控制由什么API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以很多LED手电筒API的问题为Android。我不敢问另一个,但在这里不用..

So many LED flashlight API questions for Android. I'm afraid to ask yet another, but here goes..

使用尝试和真正的FLASH_MODE_TORCH我能够达到满意我的三星Galaxy SII,并得到了LED闪光灯开启。在我朋友的Galaxy Nexus的,没有这样的运气。也没有对我的其他朋友的Droid X的。

Using the tried and true FLASH_MODE_TORCH I am able to achieve satisfaction with my Samsung Galaxy SII and get the LED flash turned on. On my friend's Galaxy Nexus, no such luck. Nor on my other friend's Droid X.

我注意到了设备的不小一些特定的本地ioctl调用似乎是必须的。这是针对Galaxy Nexus的情况?如何找到一个参考方案呢?

I'm noticing for a not insignificant number of devices specific native IOCTL calls seem to be required. Is this the case for the Galaxy Nexus? How do I find a reference to program it?

我做的标准FLASH_MODE_TORCH /闪光模式=火炬,开始preVIEW()链。

I am doing the standard FLASH_MODE_TORCH/"flash-mode"="torch", startPreview() chain.

类令人失望的是这个看似标准的API不显得那么普遍的毕竟。

Kind of disappointing that this seemingly standard API doesn't appear to be so universal after all.

推荐答案

我发现的是,有些设备需要一个SurfaceView打开LED。

What I found out is that some devices need a SurfaceView to turn on the LED.

SurfaceView preview = (SurfaceView) findViewById(R.id.PREVIEW);
SurfaceHolder mHolder = preview.getHolder();
mHolder.addCallback(this);
Camera mCamera = Camera.open();
mCamera.setPreviewDisplay(mHolder);

// Turn on LED  
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);      
mCamera.startPreview();

...

// Turn off LED
Parameters params = mCamera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
mCamera.stopPreview();
mCamera.release();

您的活动需要实现SurfaceHolder.Callback:

Your activity needs to implement SurfaceHolder.Callback:

public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {}

public void surfaceCreated(SurfaceHolder holder) {
    mHolder = holder;
    mCamera.setPreviewDisplay(mHolder);
}

public void surfaceDestroyed(SurfaceHolder holder) {
    mCamera.stopPreview();
    mHolder = null;
}

该surfaceview有可见,安卓知名度=隐形或0的高度和宽度将无法正常工作。不幸的是我没有找到一个很好的解决方案,以隐藏它,所以我 只是给它1x1dip的大小和位置它下面的按钮。

The surfaceview has to be visible, android:visibility="invisible" or a height and width of 0 won't work. Unfortunately I didn't find a good solution to hide it, so I just gave it a size of 1x1dip and positioned it underneath a button..

**(扩大在上述第[没有足够的代表回答,但认为这是有益])在某处你的当前内容查看XML,你想要的:

**(To expand on above paragraph [Don't have enough rep to reply, but felt it was useful]) Somewhere in the XML of your current Content View, you want:

<SurfaceView
    android:id="@+id/PREVIEW"
    android:layout_width="1dip"
    android:layout_height="1dip"/>

如果您有它内部的RelativeLayout的(preferred),你也可以做alignParentLeft /下掖在一个角落里。此方法适用于我的Galaxy Nexus的,但它是一个已知的问题(手机端)的Droid X的(与0.621更新,反正),并且不会对我的工作。伟大的答案,timosch!

If you have it inside a RelativeLayout (preferred), you can also do alignParentLeft/Bottom to tuck it in a corner. This method works for my Galaxy Nexus, but it's a known problem (phone-side) for Droid X (with the .621 update, anyway), and doesn't work on mine. Great answer, timosch!

这篇关于LED手电筒Galaxy Nexus的控制由什么API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆