Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get android lockscreen package name

Is there a way to get the android lockscreen package name?

I want to show alert on the lockscreen using AlertDialog.Builder. So I need to know when the lockscreen is active and what it's package name.

like image 276
Ilya Gazman Avatar asked Mar 30 '26 02:03

Ilya Gazman


1 Answers

You can detect if the lockscreen is shown with:

((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode();

And you can get the current top activity with:

(ActivityManager) getSystemService(Service.ACTIVITY_SERVICE).getRunningTasks(1).get(0).topActivity;

This will usually be the lockscreen activity, but it is possible that for example the phone app is shown while the lockscreen is active: in this case it will be the phone activity.

You will need the android.permission.GET_TASKS permission for this to work.

like image 182
Arjan Mels Avatar answered Apr 02 '26 23:04

Arjan Mels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!