問題描述
我不知道如何使用 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 閃光燈)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!