如何打开相机闪光灯以编程方式在Android的? [英] How to turn on camera flash light programmatically in Android?
问题描述
我想只打开相机闪光灯(不带摄像头preVIEW)编程的机器人。我用Google搜索,但帮助我发现叫我去此页
I want to turn on only the camera flash light (not with camera preview) programmatically in Android. I googled for it but the help i found referred me to this page
有没有人有任何联系或来样code?
Does anyone have any links or sample code?
推荐答案
对于这个你应该做这样的:
For this you should do like :
-
检查闪光灯是否 可用?
Check whether flash light is available or not ?
如果是的话那么关闭/开启
If yes then Turn Off/On
如果没有,那么你可以任何根据您的应用程序做的。 需要
If no then you can do whatever according to your app. needs
对于检查闪光可用性在设备:
您可以使用以下
context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
这将返回true,如果闪存可用,否则为false。
which will return true if a flash is available, false if not.
请参阅<一href="http://developer.android.com/reference/android/content/pm/PackageManager.html">http://developer.android.com/reference/android/content/pm/PackageManager.html了解更多信息。
对于开/关手电筒打开:
我GOOGLE了出去,上了这一下android.permission.FLASHLIGHT。 Android的舱单的许可看起来很有希望:
I googled out and got this about android.permission.FLASHLIGHT. Android manifests' permission looks promising:
<!-- Allows access to the flashlight -->
<permission android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal"
android:label="@string/permlab_flashlight"
android:description="@string/permdesc_flashlight" />
然后利用相机并设置<一个href="http://developer.android.com/reference/android/hardware/Camera.Parameters.html">Camera.Parameters.此处所使用的主要参数是<一个href="http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FLASH_MODE_TORCH">FLASH_MODE_TORCH.
Then make use of Camera and set Camera.Parameters. The main parameter used here is FLASH_MODE_TORCH.
如:
code片段,打开相机闪光灯。
Code Snippet to turn on camera flash light.
Camera cam = Camera.open();
Parameters p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
code段关闭摄像头LED灯。
Code snippet to turn off camera led light.
cam.stopPreview();
cam.release();
我刚刚发现,使用该权限的项目。检查快速设置SRC code。在这里 HTTP://$c$c.google.com/p/quick-settings/ (注:此链接现在是打破)
I just found a project that uses this permission. Check quick-settings' src code. here http://code.google.com/p/quick-settings/ (Note: This link is now broken)
有关手电筒直接看<一href="http://$c$c.google.com/p/quick-settings/source/browse/trunk/quick-settings/#quick-settings/src/com/bwx/bequick/flashlight">http://$c$c.google.com/p/quick-settings/source/browse/trunk/quick-settings/#quick-settings/src/com/bwx/bequick/flashlight (注:此链接现在是打破)
For Flashlight directly look http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/#quick-settings/src/com/bwx/bequick/flashlight (Note: This link is now broken)
Update6 你也可以尝试添加一个SurfaceView作为这个答案<一个描述href="http://stackoverflow.com/questions/8876843/led-flashlight-on-galaxy-nexus-controllable-by-what-api/9379765#9379765">LED手电筒Galaxy Nexus的控制由什么API? 这似乎是解决方案,许多手机上的作品。
Update6 You could also try to add a SurfaceView as described in this answer LED flashlight on Galaxy Nexus controllable by what API? This seems to be solution that works on many phones.
更新5 主要更新
我已经找到替代的链接(上述损坏的链接):<一href="http://www.java2s.com/Open-Source/Android/Tools/quick-settings/com.bwx.bequick.flashlight.htm">http://www.java2s.com/Open-Source/Android/Tools/quick-settings/com.bwx.bequick.flashlight.htm现在,您可以使用这个链接。 [更新:14/9/2012此链接现在是打破]
I have found alternate Link(for above broken links): http://www.java2s.com/Open-Source/Android/Tools/quick-settings/com.bwx.bequick.flashlight.htm You can now use this link. [Update : 14/9/2012 This link is now broken]
更新1
另一种开放源代码code: <一href="http://$c$c.google.com/p/torch/source/browse/">http://$c$c.google.com/p/torch/source/browse/
Another OpenSource Code : http://code.google.com/p/torch/source/browse/
更新2
示例,演示如何使LED在摩托罗拉Droid: HTTP://$c$c.google。 COM / P / droidled /
Example showing how to enable the LED on a Motorola Droid : http://code.google.com/p/droidled/
另一个开源$ C $ C:
Another Open Source Code :
HTTP://$c$c.google.com/p/covedesigndev/
HTTP://$c$c.google.com/p/search-light/
http://code.google.com/p/covedesigndev/
http://code.google.com/p/search-light/
更新3(对于小部件开启/关闭摄像头LED)
如果你想开发一个小部件,打开/关闭你的摄像头LED,那么你必须参考我的回答<一href="http://stackoverflow.com/questions/7515309/widget-for-turning-on-off-camera-flashlight-in-android/8257771#8257771">Widget为开/关摄像头手电筒安卓打开。
If you want to develop a widget that turns on/off your camera led, then you must refer my answer Widget for turning on/off camera flashlight in android..
更新4
如果你想设置光摆脱摄像头的强度LED可以参考<一个href="http://stackoverflow.com/questions/5970188/can-i-change-the-led-intensity-of-an-android-device">Can更改Android设备的LED亮度?满后..请注意,只有扎根HTC设备支持此功能。
If you want to set intensity of light emerging from camera LED you can refer Can I change the LED intensity of an Android device? full post.. Note that only rooted HTC devices support this feature.
的问题:
也有一些问题,同时打开/关闭手电筒。例如。对于设备没有 FLASH_MODE_TORCH
或者即使有,那么手电筒多年平均值开启等。
There are also some problems while turning On/Off flashlight. eg. for the devices not having FLASH_MODE_TORCH
or even if it has, then flashlight doesnot turn ON etc.
通常情况下三星产生了很多问题。
Typically Samsung creates alot of problems.
您可以参考有关问题的文章给出:
You can refer about problems in the given below list:
<一个href="http://stackoverflow.com/questions/6939816/turn-on-off-camera-led-flash-light-in-samsung-galaxy-ace-2-2-1-galaxy-tab">Turn在三星Galaxy王牌2.2.1与放大器的开/关摄像头LED /闪光灯; Galaxy Tab的
这篇关于如何打开相机闪光灯以编程方式在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!