How do I get android lockscreen package name
Asked Answered
H

3

3

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.

Honeycomb answered 19/10, 2012 at 10:33 Comment(0)
H
0

Found a native solution. After you build the Alert dialog and before showing it, apply this:

AlertDialog alertDialog = new AlertDialog.Builder(context).create();
        alertDialog.getWindow().setType(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        alertDialog.show();

This will show the dialog on top of the lock screen.

Honeycomb answered 9/12, 2014 at 15:21 Comment(2)
@llya_Gazman it si not working, is there any permission required.Cuthbertson
@FaisalAhsan Nop, no permissions. developer.android.com/reference/android/view/…Honeycomb
D
2

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.

Distasteful answered 2/6, 2013 at 8:27 Comment(0)
B
0

Really a Simple solution.

KeyguardManager km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);

if( km.inKeyguardRestrictedInputMode()) {
               //it is locked

                  }
Badajoz answered 9/12, 2014 at 9:57 Comment(0)
H
0

Found a native solution. After you build the Alert dialog and before showing it, apply this:

AlertDialog alertDialog = new AlertDialog.Builder(context).create();
        alertDialog.getWindow().setType(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        alertDialog.show();

This will show the dialog on top of the lock screen.

Honeycomb answered 9/12, 2014 at 15:21 Comment(2)
@llya_Gazman it si not working, is there any permission required.Cuthbertson
@FaisalAhsan Nop, no permissions. developer.android.com/reference/android/view/…Honeycomb

© 2022 - 2024 — McMap. All rights reserved.