【发布时间】:2011-11-08 18:57:18
【问题描述】:
因为我刚开始使用 Android 编码,所以我犹豫是否要发布我的问题,但现在我已经到了无法抗拒的地步。
我有一项服务可以打开相机 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 进行了测试,考虑到屏幕超时,它并没有关闭。 但由于不需要打开屏幕,我不想使用完整的唤醒锁。
用于我手机的 Cyanogenmod(HTC Legend)带来了一个可以做我想做的事情的手电筒应用程序。
它的源代码在这里:
https://github.com/CyanogenMod/android_packages_apps_Torch/tree/gingerbread/src/net/cactii/flash2
我注意到该应用程序的灯会短暂关闭,如果这是对某人的提示,显然不是对我;(
我不希望有人更改我的代码来做我想做的事 但如果有人能指出我正确的方向,我将不胜感激!
问候
SJ
【问题讨论】:
标签: android camera wakelock led flashlight