当 phone 被锁定并且 activity 禁用键盘保护时键盘不显示
keyboard not showing when phone is locked and an activity disables keyguard
我 运行 遇到 Android 6.0 的问题。 Marshmallow 已从官方 Nexus 出厂固件映像站点 (https://developers.google.com/android/nexus/images) 加载到 Nexus 6。
我有一个应用程序,我在其中使用 AlarmManager 启动禁用键盘锁的 activity,因此即使 phone 被锁定,activity 也可以看到(就像闹钟应用程序一样)做)。
在此 activity 中,如果用户单击按钮,则会打开一个对话框,用户应在其中键入 EditText 视图。当对话框显示或用户单击 EditText 时,它应该打开键盘。
到目前为止,这一直有效,似乎在我的 Nexus 6 上的每个 OS 版本都有效,但 6.0 除外。
我怀疑原因是Activity启动时phone被锁定,就好像我在phone解锁时启动Activity然后键盘显示完美。这似乎只发生在 6.0.
任何人都可以证实这一点,或者让我知道 6.0 中是否发生了我不知道的某些更改?
谢谢。
我终于找到了可行的解决方案。对话框 windows 似乎在 Marshmallow 中有自己的标志,必须下注设置。我在 AlertDialog 中是这样做的:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("My Title");
// Add other stuff for AlertDialog here
AlertDialog alertDialog = builder.create();
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
alertDialog.show();
对于我的 PreferenceActivity
,我不得不扩展 EditTextPreference
以解决问题,然后在 XML 中使用 myappname.TextPref
而不是 EditTextPreference
配置文件。
class TextPref extends EditTextPreference {
public TextPref(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
Dialog dialog = getDialog();
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
我 运行 遇到 Android 6.0 的问题。 Marshmallow 已从官方 Nexus 出厂固件映像站点 (https://developers.google.com/android/nexus/images) 加载到 Nexus 6。
我有一个应用程序,我在其中使用 AlarmManager 启动禁用键盘锁的 activity,因此即使 phone 被锁定,activity 也可以看到(就像闹钟应用程序一样)做)。 在此 activity 中,如果用户单击按钮,则会打开一个对话框,用户应在其中键入 EditText 视图。当对话框显示或用户单击 EditText 时,它应该打开键盘。 到目前为止,这一直有效,似乎在我的 Nexus 6 上的每个 OS 版本都有效,但 6.0 除外。
我怀疑原因是Activity启动时phone被锁定,就好像我在phone解锁时启动Activity然后键盘显示完美。这似乎只发生在 6.0.
任何人都可以证实这一点,或者让我知道 6.0 中是否发生了我不知道的某些更改?
谢谢。
我终于找到了可行的解决方案。对话框 windows 似乎在 Marshmallow 中有自己的标志,必须下注设置。我在 AlertDialog 中是这样做的:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("My Title");
// Add other stuff for AlertDialog here
AlertDialog alertDialog = builder.create();
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
alertDialog.show();
对于我的 PreferenceActivity
,我不得不扩展 EditTextPreference
以解决问题,然后在 XML 中使用 myappname.TextPref
而不是 EditTextPreference
配置文件。
class TextPref extends EditTextPreference {
public TextPref(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
Dialog dialog = getDialog();
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}