如何通过编程方式Android的意图关闭照相机的闪光灯? [英] How to turn off Flash light of Camera through intents in Android Programatically?

查看:272
本文介绍了如何通过编程方式Android的意图关闭照相机的闪光灯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何关闭照相机的闪光灯光线透过意图在Android的编程方式?

How to turn off Flash light of Camera through intents in Android Programatically?

我用下面的code激活相机应用程序,然后拍摄照片,并回到我的申请。

I use the below code for activating Camera application and then taking the picture and get back to my application.

String packageName = takePictureIntent.resolveActivity(packageManager).getPackageName();
if (mPhotoFileUri != null)
      getActivity().grantUriPermission(packageName, mPhotoFileUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoFileUri);

startActivityForResult(takePictureIntent, TAKE_PICTURE);

我想关闭相机闪光灯时,其开default.How其可能的?

I want to turn off Camera flash when its open by default.How its possible?

建议将AP preciated: - )

Suggestions will be appreciated:-)

推荐答案

对于这个你应该做这样的:

1)检查闪光灯是否可用?

1) Check whether flash light is available or not ?

2)如果是然后关闭/开启

2) If yes then Turn Off/On

3)如果没有,那么你可以任何根据您的应用程序做的。需要

3) If no then you can do whatever according to your app. needs

对于设备检查闪光的可用性:

您可以使用以下

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

如果闪存可用,否则为false,将返回true。

which will return true if a flash is available, false if not.

请参阅链接以获取更多信息。

See link for more information.

有关接通/关断手电筒:

For turning on/off flashlight :

我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" />

然后使用相机并设置Camera.Parameters。这里使用的主要参数是的 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();

问题:

有也同时开启/关闭手电筒一些问题。例如。对于设备没有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:

1)的Andr​​oid 使用相机闪光灯

1) Use camera flashlight in Android

2)<一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的

参考链接:
<一href=\"http://stackoverflow.com/questions/6068803/how-to-turn-on-camera-flash-light-programmatically-in-android\">How在Android的编程方式打开相机闪光灯?

这篇关于如何通过编程方式Android的意图关闭照相机的闪光灯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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