سؤال

I want to check programatically if my device is locked by a third party Lockscreen...With the normal Lockscreen by android you can do that by

KeyguardManager kgMgr = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean locked = kgMgr.inKeyguardRestrictedInputMode();

But what if a third party Lockscreen is installed?! Is there any way to check if the device is locked?

هل كانت مفيدة؟

المحلول

You can get the foreground app and check for its permissions using the PackageManager class. To get the foreground application you can go through this link.

Once you get the foreground app, you can fetch the permissions of that app. Check this link for this functionality.

Later, You can check whether its a system app or not by going through getApplicationInfo and later & with ApplicationInfo.FLAG_SYSTEM. You can check this link on how to do that.

نصائح أخرى

I think that all custom lockscreens use the <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> permission. So your method should be correct in most of standard cases.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top