gpt4 book ai didi

android - 解锁 android 不适用于 FLAG_DISMISS_KEYGUARD

转载 作者:行者123 更新时间:2023-11-29 16:04:43 25 4
gpt4 key购买 nike

这是我的代码,从其他关于解锁 android 的主题复制和粘贴..我不知道为什么这不起作用! :(

目标是:当接近传感器为 HI 时,设备会自行解锁。

(更多信息:Using proximity sensor lock and unlock a home screen)

传感器工作正常,但手机仍然处于锁定状态:(

我没有 pin 锁或其他,我部署在 nexus 5 上。

private SensorManager mSensorManager;       
private Sensor ProxymitySensor ;
private ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_unlock);

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
ProxymitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mSensorManager.registerListener(this, ProxymitySensor,SensorManager.SENSOR_DELAY_NORMAL);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.unlock, menu);
return true;
}


@Override
public final void onSensorChanged(SensorEvent event) {
Object sensordata = event.values[0];
// Do something with this sensor data.
if (event.values[0] == event.sensor.getMaximumRange()){
PlaySound();
UnlockMe();
}
}

private void PlaySound() {
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
}

private void UnlockMe(){
// try to unlock the phone
getWindow().addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
// nothing happen :(
}



@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}

这里是完整的文件:http://pastebin.com/CCv2W70Y

我的手机被锁定了,如果我 Handlebars 放在上面,我只会听到哔哔声,仅此而已:(LocCat 不要说 anityng...

有什么想法吗?

最佳答案

您缺少全屏标志。

来自谷歌的文档:

public static final int FLAG_SHOW_WHEN_LOCKED

Window flag: special flag to let windows be shown when the screen is locked. This will let application windows take precedence over key guard or any other lock screens. Can be used with FLAG_KEEP_SCREEN_ON to turn screen on and display windows directly before showing the key guard window. Can be used with FLAG_DISMISS_KEYGUARD to automatically fully dismisss non-secure keyguards. This flag only applies to the top-most full-screen window.

强调我的。

关于android - 解锁 android 不适用于 FLAG_DISMISS_KEYGUARD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20182306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com