禁用屏幕锁定(电源)按钮在安卓 [英] Disable Screen Lock(Power) Button in Android
本文介绍了禁用屏幕锁定(电源)按钮在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,当我的应用程序正在运行的电源按钮(在pressing锁定画面+屏幕变黑),应禁用。使得用户不能锁定屏幕。
I want that when my application is running the power button (which upon pressing locks the screen & screen goes BLACK), should be disabled. So that the user cannot lock the screen.
我已经注意到这件事情在三星Galaxy S手机的默认相机应用。这是同样的原因,我想这样做。我也有相关的应用程序中的摄像头。
I have noticed this thing in Samsung Galaxy S phone's Default Camera App. That's the same reason I am trying to do the same. I have also a Camera related App.
推荐答案
试试这个
int val=android.provider.Settings.System.getInt(getContentResolver(),
SCREEN_OFF_TIMEOUT);
android.provider.Settings.System.putInt(getContentResolver(),
SCREEN_OFF_TIMEOUT, -1);
Toast.makeText(this, "Disabled Screen Timeout", Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = settings.edit();
editor.putInt("ScreenTimeout",val);
editor.commit();
}
} catch(Throwable er) {
Toast.makeText(this, "Error "+er.getMessage(), Toast.LENGTH_LONG).show();
}
这将设置屏幕关闭
禁用键后卫的Android使用
to disable key guard in android use
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
和使用permition
and use permition
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
要保持屏幕活着
to keep screen alive
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
这篇关于禁用屏幕锁定(电源)按钮在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文