Android's floating windows coupled with FLAG_SHOW_WHEN_LOCKED fails

穿精又带淫゛_ 提交于 2019-12-22 04:55:16

问题


My app, shows a dialog box to the user before the lock screen. It's a simple Activity that contains DialogFragments (from the support library as this app runs on 2.2+).

Since the actual activity that displayed those dialogs was not a floating window by Android's standards,

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

worked fine.

However, I was thinking I'd use an Activity that looks like a Dialog instead. All the Dialog themes (Holo, etc), though, have this item:

<item name="android:windowIsFloating">true</item>

This, for some reason causes the window flag to be completely ignored. Interestingly, the Activity gets shown after the user unlocks the screen.

Why would this be so, and is there a way around it?


回答1:


Suffering from the same issue. The only thing that seems to work in this issue is

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

Dont forget to use the keyguard permission in manifest:

<uses-permission android:name = "android.permission.DISABLE_KEYGUARD"/>


来源:https://stackoverflow.com/questions/13410972/androids-floating-windows-coupled-with-flag-show-when-locked-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!