Reputation: 2460
I need to to register a callback to be invoked whenever the phone is locked/unlocked. This is the LockStateReceiver
class which extends BroadcastReceiver
:
public class LockStateReceiver extends BroadcastReceiver {
public static boolean CURRENT_KEYGUARD_STATE = false;
static {
Context context = VectorApplication.Companion.getAppContext();
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
CURRENT_KEYGUARD_STATE = keyguardManager.isKeyguardLocked();
}
@Override
public void onReceive(final Context context, final Intent intent) {
System.out.println(">>> keyguard state changed");
}
}
Now I want to use this receiver:
val mLockStateReceiver = LockStateReceiver()
BroadcastManager.registerSystemReceiver(
mLockStateReceiver,
IntentFilter(Intent.ACTION_KEYGUARD_LOCKED),
VectorApplication.getAppContext()
)
But there's no Intent.ACTION_KEYGUARD_LOCKED
.
Upvotes: 1
Views: 157