I want to take pictures from the Android device's camera periodically over a matter of hours, to create a time lapse video effect.
I set an Alarm Manager with an AlarmManager.RTC_WAKEUP flag set to start up a service every few minutes.
The service holds a partial wakelock, does some work, and then calls a Broadcast Receiver through the Alarm Manager which starts up an Activity.
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.
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.
So the questions I have are:
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.
Is there any way to take a picture without using a preview surface view?
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?
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?
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.
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.
This is frustrating stuff!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…