我有一个后台视频录制服务,在此期间我禁用了Keyguard。当我想要停止录制时,我会停止服务并调用OnDestroy()。
我可以在我的跟踪中看到调用了ReenableKeyguard()。但是,在我“强制停止”启动服务的主机应用程序之前,Keyguard仍然是禁用的。
是什么原因导致键盘守卫在调用ReenableKeyguard()时保持禁用状态?
这是销毁Service并重新启用keyguard的代码。(它是C#/Xamarin,但与Java基本相同)
public override void OnDestroy()
{
Tracer.Trace("BackgroundVideoRecorder::OnDestroy();");
base.OnDestroy();
try
{
camera.Reconnect();
mediaRecorder.Stop();
mediaRecorder.Reset();
camera.StopPreview();
mediaRecorder.Release();
camera.Release();
camera = null;
if (Common.KeyGuardLocker != null)
{
Tracer.Trace("BackgroundVideoRecorder::OnDestroy() - ReenableKeyguard()");
Common.KeyGuardLocker.ReenableKeyguard();
}
windowManager.RemoveView(surfaceView);
}
catch (Exception ex)
{
Tracer.Trace(ex);
}
}发布于 2015-03-01 14:11:49
I have the exact same problem and the reason was that i had only permissions to Disable keyguard and not the ones to re-enable it.android.permission.DISABLE_KEYGUARD android.permission.ENABLE_KEYGUARD
https://stackoverflow.com/questions/27267515
复制相似问题