使用 kivy/python 访问 android 手电筒(相机 LED 闪光灯) [英] Accessing android flashlight(camera LED flash) with kivy/python

查看:50
本文介绍了使用 kivy/python 访问 android 手电筒(相机 LED 闪光灯)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何使用 python 或 kivy 访问我的 android 上的 led 灯,我尝试安装 python-for-android 以便能够将 android 模块导入我的代码,但它不是模块可以'找不到.我按照此处的说明克隆了 python-for-android.我没有按照我想的那样按照该页面安装 ndk 或 sdk,因为 kivy 已经使用它们,它们已经安装了.有人可以指出我正确的方向吗?

I can't figure out how to access the led light on my android with python or kivy, I have tried installing python-for-android to be able to import the android module into my code but it's not the module can't be found. I cloned python-for-android as instructed here. I didn't install the ndk or sdk as per that page as I thought since kivy already uses them they were already installed. Can someone please point me in the right direction?

推荐答案

是的,你可以从桌面用 Kivy 编写这个应用程序,只是无法在桌面上测试它.每次都必须构建并部署到 Android 设备上进行测试.

Yes, you can write this app in Kivy from the desktop, you just won't be able to test it on the desktop. You will have to build and deploy to an Android device to test each time.

改编自如何在Android中以编程方式打开相机闪光灯?:

检查闪存功能是否可用:

To check if flash capability is available:

PythonActivity = autoclass('org.renpy.android.PythonActivity')
PackageManager = autoclass('android.content.pm.PackageManager')
pm = PythonActivity.mActivity.getPackageManager()
flash_available = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)

要使用手电筒,您的应用需要 FLASHLIGHT 和 CAMERA 权限.您可以将这些添加到 buildozer.spec 或 python-for-android 命令行.

To use the flashlight, your app will need the FLASHLIGHT and CAMERA permissions. You can add these to buildozer.spec or the python-for-android command line.

最后,打开闪光灯:

Camera = autoclass('android.hardware.Camera')
CameraParameters = autoclass('android.hardware.Camera$Parameters')
cam = Camera.open()
params = cam.getParameters()
params.setFlashMode(CameraParameters.FLASH_MODE_TORCH)
cam.setParameters(params)
cam.startPreview()

然后关闭:

cam.stopPreview()
cam.release()

这篇关于使用 kivy/python 访问 android 手电筒(相机 LED 闪光灯)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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