0

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?

davidOhara
  • 1,008
  • 5
  • 17
  • 39

2 Answers2

0

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.

Climbatize
  • 1,103
  • 19
  • 34
  • so i could get a list of all running processes and take the one with the priority that indicates that the app is in foreground. Is there a way to look into the Manifest of that app?! – davidOhara Oct 17 '13 at 08:37
0

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.

Community
  • 1
  • 1
prijupaul
  • 2,076
  • 2
  • 15
  • 17
  • But what if there is a different Application in the foreground which is not a LockScreen but also needs the "android.permission.DISABLE_KEYGUARD"?! Than i will get wrong informations... – davidOhara Oct 17 '13 at 10:17