使用 kivy/python 访问 android 手电筒(相机 LED 闪光灯)

Accessing android flashlight(camera LED flash) with kivy/python(使用 kivy/python 访问 android 手电筒(相机 LED 闪光灯))
本文介绍了使用 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 闪光灯)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)