Android的 - 我怎样才能唤醒电话从硬睡眠拍照? [英] Android - How can I wake up the phone from a hard sleep to take a picture?

查看:248
本文介绍了Android的 - 我怎样才能唤醒电话从硬睡眠拍照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借此从Android设备的相机拍摄的图片定期在几个小时内,创建一个时间推移视频效果。

I want to take pictures from the Android device's camera periodically over a matter of hours, to create a time lapse video effect.

我设置的报警管理与AlarmManager.RTC_WAKEUP标志设置启动服务每隔几分钟。

I set an Alarm Manager with an AlarmManager.RTC_WAKEUP flag set to start up a service every few minutes.

在服务端的部分wakelock,做了一些工作,然后调用的广播接收器通过报警管理器,它启动了一个活动。

The service holds a partial wakelock, does some work, and then calls a Broadcast Receiver through the Alarm Manager which starts up an Activity.

该活动创建(或恢复),打开它自己的wakelock,并设置摄像头preVIEW表面。一旦表面是设置SurfaceHolder听者的surfaceChanged()方法被调用,最终需要的图片。

The activity is created (or is resumed), turns on it's own wakelock, and sets up the camera preview surface. Once the surface is setup the SurfaceHolder listener's surfaceChanged() method is called, which finally takes a picture.

如果该设备是清醒的,一切完美的作品如预期。但是,如果该设备是睡着了,一旦活动的onResume()方法完成的活动将立即暂停。相机的preVIEW表面无法完成初始化,没有画面将永远不会考虑。

If the device is awake, everything works perfectly as expected. But if the device is asleep, once the Activity's onResume() method is finished the Activity is instantly paused. The camera's preview surface never finishes initializing, and no picture will ever be taken.

所以我的问题是:

  1. 有没有办法以编程方式唤醒了电话?我甚至尝试使用:

  1. Is there any way to wake up the phone programmatically? I even try using:

PowerManager powerManager =
            (PowerManager)this.getSystemService(Context.POWER_SERVICE);
powerManager.userActivity(SystemClock.currentThreadTimeMillis(),false);

但是,这并不唤醒了电话,如果它是睡着了。

But that doesn't wake up the phone if it is asleep.

  1. 有没有什么办法可以拍摄照片时不使用preVIEW表面观?

  1. Is there any way to take a picture without using a preview surface view?

有没有办法采取不依赖于异步回调的照片吗?我可以把所有的code。在活动onResume()方法来拍照?

Is there a way to take a picture that doesn't rely on asynchronous callbacks? Can I put all the code in the Activities onResume() method to take a picture?

有没有什么办法让活动的onResume()方法中运行足够长的时间,使摄像机的preVIEW有足够的时间进行初始化,并呼吁所有的听众?

Is there any way to keep the Activity's onResume() method running long enough so that the camera's preview has enough time to initialize and call all the listeners?

我现在用的是wakelocks正确的,我有所有的权限被设置适当的清单文件。我的行为没有保持清醒足够长的异步监听器才能正常工作。

I am using the wakelocks correctly, and I have all the permission's set properly in the manifest file. My activity isn't kept awake long enough for the asynchronous listeners to properly work.

和以化合物的问题,我试图让一切的Andr​​oid 1.6兼容的,因为这是唯一的测试设备我有机会获得。

And to compound the issue, I'm trying to keep everything Android 1.6 compatible, because that is the only test device I have access to.

这是令人沮丧的东西!

推荐答案

我终于得到了现在的地方。

I have finally gotten somewhere now.

我在使用这两个标志来创建wakelock

I have to create a wakelock using these two flags

PowerManager.SCREEN_BRIGHT_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb");
wl.acquire();

然后器件唤醒,并开始在键盘锁屏。

Then the device wakes up, and starts at the keyguard screen.

不过,我可以让过去的键盘锁屏和拍照的唯一方法是将活动的窗口上使用这些标志:

But the only way I can get past the keyguard screen and take a picture is to use these flags on the Activity's window:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

但是,这仅适用于Android的2.0和1.6无法正常工作。

But this is only available with Android 2.0, and doesn't work in 1.6.

这篇关于Android的 - 我怎样才能唤醒电话从硬睡眠拍照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆