I'm making a lock screen app that uses a foreground service which disables the keyguard when it is started and reenables it when it is destroyed. I can disable it fine, but it doesn't reenable when the service is stopped. I'm stopping the service in an activity, and I know the onDestroy() is being called because the notification goes away. My code in the service:
@Override
public void onDestroy() {
isRunning = false;
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Service.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.reenableKeyguard();
stopForeground(true);
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Service.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
Notification notification = new Notification(R.drawable.ic_launcher, getText(R.string.ticker_text),
System.currentTimeMillis());
Intent notificationIntent = new Intent(this, LockService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.notification_title),
getText(R.string.notification_message), pendingIntent);
startForeground(1, notification);
return Service.START_STICKY;
}
}