Skip to content

Instantly share code, notes, and snippets.

@yakivmospan
Last active October 30, 2017 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakivmospan/57e9358cf8dad6ddca789133e4cbf089 to your computer and use it in GitHub Desktop.
Save yakivmospan/57e9358cf8dad6ddca789133e4cbf089 to your computer and use it in GitHub Desktop.
private val keyguardManager: KeyguardManager
init {
keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
}
fun isDeviceSecure(): Boolean = if (hasMarshmallow()) keyguardManager.isDeviceSecure else keyguardManager.isKeyguardSecure
// Used to block application if no lock screen is setup.
fun showDeviceSecurityAlert(): AlertDialog {
return AlertDialog.Builder(context)
.setTitle(R.string.lock_title)
.setMessage(R.string.lock_body)
.setPositiveButton(R.string.lock_settings, { _, _ -> context.openLockScreenSettings() })
.setNegativeButton(R.string.lock_exit, { _, _ -> System.exit(0) })
.setCancelable(BuildConfig.DEBUG)
.show()
}
fun hasMarshmallow() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment