kivy / plyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs
https://plyer.readthedocs.io
MIT License
1.62k stars 428 forks source link

How to turn on a flashlight on a phone with Android 9? #668

Open Andrukva opened 2 years ago

Andrukva commented 2 years ago

Please tell me how to turn on the flashlight on a phone with Android 9 using plyer and kivy/switch or kivy/button. Those examples that exist do not work. The application starts, but as soon as I press the button to turn on the flashlight, the application closes. Please show me how to do it correctly. Thank you in advance!

HyTurtle commented 2 years ago

Android Permissions would be needed to be granted for various plyer/pyjnius features - for flash(light) have you requested CAMERA permission?

Otherwise could you get a crash report via logcat - to see a reason for the crash.

Andrukva commented 2 years ago

I requested permission when assembling in a bulldozer, as shown in the example.

Andrukva commented 2 years ago

I requested permission for both the camera and the flashlight.

HyTurtle commented 2 years ago

Just checked and flash.on() and flash.off() runs fine here on Android 11. Did you request camera at runtime ie within the app. If not you can do so manually with your current app in Settings > Apps

Otherwise again - would ideally want to see the log report.

Andrukva commented 2 years ago

Could you show me what code you tried?

Andrukva commented 2 years ago

Strangely, my application is not in the list of applications that are allowed or not allowed to use the camera. Although in the specification of the bulldozer I specified both the camera and the flash

oukiar commented 2 years ago

I think this issue was solved by this pull request #716

Tested under android 5.

If you want to test change the requirements in your buildozer.spec requirements = kivy, git+https://github.com/oukiar/plyer.git

and do buildozer android clean

best regards

oukiar commented 2 years ago

Some updates, today i was able to test in android 9 and my surprise is that using the legacy camera api not work.

For get working the flashlight was added code for use the CameraManager (newer api) now it is working and tested on android 9 device, maybe will work on other android versions, tests are necesary.