Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.KeyguardManager;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.provider.Settings;
- import android.util.Log;
- public class LockTest {
- public static boolean doesDeviceHaveSecuritySetup(Context context)
- {
- return isPatternSet(context) || isPassOrPinSet(context);
- }
- /**
- * @param context
- * @return true if pattern set, false if not (or if an issue when checking)
- */
- public static boolean isPatternSet(Context context)
- {
- ContentResolver cr = context.getContentResolver();
- try
- {
- int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED);
- return lockPatternEnable == 1;
- }
- catch (Exception e)
- {
- Log.e("==========",e.getMessage());
- return false;
- }
- }
- /**
- * @param context
- * @return true if pass or pin set
- */
- public static boolean isPassOrPinSet(Context context)
- {
- KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); //api 16+
- return keyguardManager.isKeyguardSecure();
- }
- }
Add Comment
Please, Sign In to add comment