Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top