Himanshu Virmani
Himanshu Virmani

Reputation: 2460

android FLAG_SHOW_WHEN_LOCKED not working

I am trying to get my application over the lock screen for some input from user, but unable to
do so.

I have tried the following lines in onCreate as well as onAttachToWindow callbacks but nothing seems to wor

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

I have checked most questions on stackoverflow and they all point to the above mentioned solution.

Do we need to use any permission or am I missing anything. I am working on a rooted galaxy S

Upvotes: 1

Views: 7193

Answers (5)

Bruce
Bruce

Reputation: 2196

I meet the same problem, the solution is remove the setType line in your activity. (If you already add that)

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    //getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}

Upvotes: 0

Daniel Höh
Daniel Höh

Reputation: 11

I had the same problem and I can confirm that the problem is the dialog theme. It seems that the attribute android:windowIsFloating is responsible that a dialog is not shown on top of the lock screen. That attribute is set to true in the Holo dialog themes.

But if you derive your Holo dialog theme to an own style like this:

<style name="ReminderAlarmDialog" parent="@android:style/Theme.Holo.Dialog">
    <item name="android:windowIsFloating">false</item>
</style>

the dialog activity will be shown on top of the lock screen. Only problem: The dialog will then fill the entire screen and thus, it doesn't look very well. So it is not a real solution, only an explanation why dialog themes don't work.

Upvotes: 0

almisoft
almisoft

Reputation: 2183

Note that your activity should not be a dialog. I had defined in Manifest:

<activity
    android:name="TestDialog"
    android:theme="@android:style/Theme.Dialog" >
</activity>

After I removed the theme, it worked and the activity was displayed over any lock screen. Maybe you can simulate a dialog with the help of the style @android:style/Theme.Translucent.

Upvotes: 3

Himanshu Virmani
Himanshu Virmani

Reputation: 2460

The answer to this issue is

Android's floating windows coupled with FLAG_SHOW_WHEN_LOCKED fails

Cannot use floating window along with FLAG_SHOW_WHEN_LOCKED

Upvotes: 0

Himanshu Virmani
Himanshu Virmani

Reputation: 2460

The answer suggested below is also not working...The only option left for me now is adding permission for disable keygaurd in manifest and using

KeyguardManager  myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); myLock = myKeyGuard.newKeyguardLock(); myLock.disableKeyguard();

I don't want to add a new permission because that will make my application come in manual updates instead of automatic update. :(

Upvotes: 0

Related Questions