安卓:保持相机的LED屏幕关闭后

编程入门 行业动态 更新时间:2024-10-26 16:34:15
本文介绍了安卓:保持相机的LED屏幕关闭后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因为我在一开始与Android编码我犹豫了一下后,我的问题,但现在我在的地步,我无法抗拒。

since i'm at the beginning with Android coding i hesitated to post my question, but now i'm at the point where i can't resist.

我有打开相机,LED的onCreate服务:

I have a service which turns on the camera-LED onCreate:

@Override public void onCreate() { // make sure we don't sleep this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE); this.mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SleepLED"); this.mTimer = new Timer(); this.mTimerTask = new TimerTask() { public void run() { // turn on the LED setFlashlight(Camera.Parameters.FLASH_MODE_TORCH); mWakeLock.acquire(); } }; // Get the notification-service this.mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // Display a notification about us starting. We put an icon in the status bar. showNotification(); // Open camera this.frontCam = Camera.open(); this.frontCamPara = frontCam.getParameters(); this.frontCam.lock(); // Schedule the TimerTask this.mTimer.schedule(mTimerTask, 0); }

我可以告诉大家,WakeLock收购,我测试了FULL_WAKE_LOCK并没有关掉考虑屏幕超时。 不过,由于屏幕并不需要对我不希望使用全wakelock。

I can tell that the WakeLock acquires, I tested with FULL_WAKE_LOCK and it didn't turn off considering Screen Time-Out. But since the Screen isn't need to be on I don't want to use the full wakelock.

的CyanogenMod的为我的手机(HTC传奇)带来了火炬应用程序,它可以做我想做的。 它的源$ C ​​$ c是在这里: github/CyanogenMod/android_packages_apps_Torch/tree/gingerbread/src/net/cactii/flash2 我发现灯熄灭了片刻与应用程序,如果这是一个提示的人,显然不适合我;(

The Cyanogenmod for my phone (HTC Legend) brings an torch-app which can do what i want. Its source code is here: github/CyanogenMod/android_packages_apps_Torch/tree/gingerbread/src/net/cactii/flash2 I noticed that the light turns off for a short moment with that app, if this is a hint for someone, obviously not for me ;(

我不希望别人改变我的code做我想要什么 但我会很感激,如果任何人都可以点我在正确的方向!

I don't expect someone to change my code to do what i want but I'd be thankful if anyone could point me in the right direction!

电贺 SJ

推荐答案

我已经找到了解决问题的办法。 当手机关闭屏幕它禁用相机的LED,但它允许用户重新激活它是这样的:

I have found a solution to the problem. When the phone turns off the screen it does deactivate the camera LED, but it allows a user to reactivate it like this:

@Override public void onCreate() { // assume we start with screen on and save that state ;-) this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE); screenOn = this.pm.isScreenOn(); // program a timer which checks if the light needs to be re-activated this.mTimer = new Timer(); this.mTimerTask = new TimerTask() { public void run() { // re-activate the LED if screen turned off if(!pm.isScreenOn() && pm.isScreenOn() != screenOn) { Log.i("SleepLEDservice", "re-activated the LED"); // really it's NOT ENOUGH to just "turn it on", i double-checked this setFlashlight(Camera.Parameters.FLASH_MODE_OFF); setFlashlight(Camera.Parameters.FLASH_MODE_TORCH); } screenOn = pm.isScreenOn(); } }; } private void setFlashlight(String newMode) { try { this.frontCamPara = this.frontCam.getParameters(); if(this.frontCamPara.getFlashMode() != newMode) { this.frontCamPara.setFlashMode(newMode); this.frontCam.setParameters(frontCamPara); } } catch (Exception e) { e.printStackTrace(); } }

关键是改变状态恢复到FLASH_MODE_OFF,比回FLASH_MODE_TORCH。

The key is changing the state back to FLASH_MODE_OFF and than back to FLASH_MODE_TORCH.

更多推荐

安卓:保持相机的LED屏幕关闭后

本文发布于:2023-11-27 10:05:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:屏幕   相机   LED

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!