关闭相机,LED闪光灯开/关与SL4A的Python [英] Turn camera flash LED on/off with SL4A Python

查看:604
本文介绍了关闭相机,LED闪光灯开/关与SL4A的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能打开相机SL4A Python的开启和关闭LED?最大强度是确定的。

在任何Android的。*?

这里的code:

 进口SYS高清toggle_LED(动作=上):
    如果行动=='对':
        开放('/ SYS /班/ LED灯/手电筒闪光/ flash_light','W')表示:
            on.write('1')
    ELIF行动=='关':
        开放('/ SYS /班/ LED灯/手电筒闪光/ flash_light','W'),其为:
            off.write(0)
如果__name__ =='__main__':
    toggle_LED()
    而真正的:
        如果条带(sys.stdin.read())[0] =='Q':
            toggle_LED(动作='断')
            sys.exit()

编辑:这款手机是华为的Ideos X5 U8800H


解决方案

  

在任何Android的。*?


您可以在Android的下列方式打开和关闭手电筒。

打开手电筒。

 相机Cam = NULL;
公共无效turnOnFlashLight(){
    尝试{
        如果(getPackageManager()。hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
            凸轮= Camera.open();
            参数P = cam.getParameters();
            p.setFlashMode(Parameters.FLASH_MODE_TORCH);
            cam.setParameters(P);
            cam.start preVIEW();
        }
    }赶上(例外五){
        e.printStackTrace();
        Toast.makeText(getBaseContext(),异常抛出打开手电筒,Toast.LENGTH_SHORT).show();
    }
}

关闭手电筒。

 公共无效turnOffFlashLight(){
    尝试{
        如果(getPackageManager()。hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)){
            cam.stop preVIEW();
            cam.release();
            凸轮= NULL;
        }
    }赶上(例外五){
        e.printStackTrace();
        Toast.makeText(getBaseContext(),异常抛出关闭手电筒,Toast.LENGTH_SHORT).show();
    }
}

不要忘了在清单中添加的权限。

 <使用许可权的android:NAME =android.permission.CAMERA/>
<使用许可权的android:NAME =android.permission.FLASHLIGHT/>

有关更多的参考:<一href=\"http://acomputerengineer.word$p$pss.com/2013/09/12/turn-on-and-turn-off-flash-light-programmatically-in-android/\"相对=nofollow>打开,并在编程关闭闪光灯的Andr​​oid

How can I turn the camera LED on and off with sl4a Python? Maximum intensity is ok.

Anything in android.* ?

Here's the code:

import sys

def toggle_LED(action="on"):
    if action == 'on':
        with open('/sys/class/leds/torch-flash/flash_light', 'w') as on:
            on.write('1')
    elif action == 'off':
        with open('/sys/class/leds/torch-flash/flash_light', 'w') as off:
            off.write('0')


if __name__ == '__main__':
    toggle_LED()
    while True:
        if strip(sys.stdin.read())[0] == 'q':
            toggle_LED(action='off')
            sys.exit()

EDIT: The phone is a Huawei Ideos X5 U8800H

解决方案

Anything in android.* ?

You can turn on and off flashlight in following manner in Android.

Turn on the flashlight.

Camera cam = null;
public void turnOnFlashLight() {
    try {
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
            cam = Camera.open();
            Parameters p = cam.getParameters();
            p.setFlashMode(Parameters.FLASH_MODE_TORCH);
            cam.setParameters(p);
            cam.startPreview();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "Exception throws in turning on flashlight.", Toast.LENGTH_SHORT).show();
    }
}

Turn off the flashlight.

public void turnOffFlashLight() {
    try {
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
            cam.stopPreview();
            cam.release();
            cam = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "Exception throws in turning off flashlight.", Toast.LENGTH_SHORT).show();
    }
}

Do not forgot to add permission in manifest.

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>

For more reference: Turn on and turn off flash light programmatically in Android

这篇关于关闭相机,LED闪光灯开/关与SL4A的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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