要想android在开机启动完成时不锁屏,而且不影响其他情况下的锁屏特性,只需修改KeyguardViewMediator.java,在onSystemReady方法中注释掉对doKeyguard的调用即可。KeyguardViewMediator.java代码目录
frameworks/policies/base/phone/com/android/internal/policy/impl/
Android锁屏时会先调用onPause();解锁时调用onResume,读入保存的应用程序的资源。如果运行程序时已经锁屏,应用程序会先调用onCreate(),然后onResume(),再则onPause()。
取消锁屏:<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>KeyguardManager mKeyGuardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("自己Activity名字");mLock.disableKeyguard();
也是相当的简单了,但基于Rexsee的API,可以通过一句话搞定。1. 取消锁屏:window.setTimeout('rexseeKeyguard.disable();alert(\'自动解锁!\');',10000);alert('请按电源键关屏再开屏看到锁屏画面,10秒后自动解锁。')2. 启动锁屏:rexseeKeyguard.reEnable();
如下是源码
01
/*
02
* Copyright (C) 2011 The Rexsee Open Source Project
03
*
04
* Licensed under the Rexsee License, Version 1.0 (the "License");
05
* you may not use this file except in compliance with the License.
06
* You may obtain a copy of the License at
07
08
* http://www.rexsee.com/CN/legal/license.html
09
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
package rexsee.core.alarm;
18
19
import rexsee.core.browser.JavascriptInterface;
20
import rexsee.core.browser.RexseeBrowser;
21
import android.app.KeyguardManager;
22
import android.app.KeyguardManager.KeyguardLock;
23
import android.content.Context;
24
25
public class RexseeKeyguard implements JavascriptInterface {
26
27
private static final String INTERFACE_NAME = "Keyguard";
28
@Override
29
public String getInterfaceName() {
30
return mBrowser.application.resources.prefix + INTERFACE_NAME;
31
}
32
33
public JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) {
34
return this;
35
36
37
public JavascriptInterface getNewInterface(RexseeBrowser childBrowser) {
38
return new RexseeKeyguard(childBrowser);
39
40
41
private final Context mContext;
42
private final RexseeBrowser mBrowser;
43
private KeyguardLock mKeyguardLock = null;
44
45
public RexseeKeyguard(RexseeBrowser browser) {
46
mBrowser = browser;
47
mContext = browser.getContext();
48
49
public RexseeKeyguard(Context context) {
50
mBrowser = null;
51
mContext = context;
52
53
54
//JavaScript Interface
55
56
public void enable() {
57
58
try {
59
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
60
dpm.lockNow();
61
} catch (Exception e) {
62
mBrowser.exception(getInterfaceName(), e);
63
64
65
66
public void reEnable() {
67
if (mKeyguardLock != null) {
68
mKeyguardLock.reenableKeyguard();
69
mKeyguardLock = null;
70
71
72
public void disable() {
73
KeyguardManager keyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
74
mKeyguardLock = keyguardManager.newKeyguardLock("");
75
mKeyguardLock.disableKeyguard();
76
77
78
常常我们开 发程序的时候我们不需要系统唤醒系统锁屏功能,比如我们在做xxxNowTV或XXX播放器这样的程序,用户有时候在看电视或视频的时候不希望系统的锁屏 功能启动,既不想锁频,然而系统却在我们看电视或者视频的时候出来个锁屏的界面进行锁频拉,我们还要想继续看的话还要去解锁,这样好麻烦,不是我们想要 的,那我们该怎么做呢,其实很简单,我这里只讲其中的两种
一 :我们只要在程序中用代码实现。代码如下: