论坛首页 移动开发技术论坛

android锁屏 诡异的问题

浏览 9380 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-09-27  
夜之son 写道
jeye_ID 写道
楼主能说下解决方法吗,我也遇到了这个问题

 

这是一个开源项目里关于锁的控制,代码写的很好,你自己看看吧。public class ManageKeyguard {

private static KeyguardManager myKM = null;
private static KeyguardLock myKL = null;

public static final String TAG = "kg";

public static synchronized void initialize(Context context) {
  if (myKM == null) {
    myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    Log.v("MKinit","we had to get the KM.");
  }
}

public static synchronized void disableKeyguard(Context context) {
  // myKM = (KeyguardManager)
  // context.getSystemService(Context.KEYGUARD_SERVICE);
  initialize(context);

  if (myKM.inKeyguardRestrictedInputMode()) {
    myKL = myKM.newKeyguardLock(TAG);
    myKL.disableKeyguard();
    //Log.v(TAG,"--Keyguard disabled");
  } else {
    myKL = null;
  }
}

//the following checks if the keyguard is even on...
//it actually can't distinguish between password mode or not
//I've learned that this returns true even if you've done the above disable
//that's because disable is just hiding or pausing the lockscreen.

//the only time this returns false is if we haven't ever done an init
//or we have already securely exited
//the OS also seems to automatically do a secure exit when you press home after a disable
public static synchronized boolean inKeyguardRestrictedInputMode() {
  if (myKM != null) {
    return myKM.inKeyguardRestrictedInputMode();
  }
  
  return false;
}

public static synchronized void reenableKeyguard() {
  if (myKM != null) {
    if (myKL != null) {
      myKL.reenableKeyguard();
      myKL = null;
    }
  }
}

//this only can be used after we have paused/hidden the lockscreen with a disablekeyguard call
//otherwise the OS logs "verifyunlock called when not externally disabled."
public static synchronized void exitKeyguardSecurely(final LaunchOnKeyguardExit callback) {
  if (inKeyguardRestrictedInputMode()) {
    Log.v(TAG,"--Trying to exit keyguard securely");
    myKM.exitKeyguardSecurely(new OnKeyguardExitResult() {
      public void onKeyguardExitResult(boolean success) {
        reenableKeyguard();
        //this call ensures the keyguard comes back at screen off
        //without this call, all future disable calls will be blocked
        //for not following the lockscreen rules
        //in other words reenable immediately restores a paused lockscreen
        //but only queues restore for next screen off if a secure exit has been done already
        if (success) {
          Log.v(TAG,"--Keyguard exited securely");
          callback.LaunchOnKeyguardExitSuccess();
        } else {
          Log.v(TAG,"--Keyguard exit failed");
        }
      }
    });
  } else {
    callback.LaunchOnKeyguardExitSuccess();
  }
}

public interface LaunchOnKeyguardExit {
  public void LaunchOnKeyguardExitSuccess();
}
 

能否gtailk或者QQ详问一下呢。。。

0 请登录后投票
   发表时间:2011-09-28  
wangju900208 写道
夜之son 写道
wangju900208 写道
夜之son 写道

最近做了个锁屏,实现方式就是抓取系统screenon和screenoff信号,已经上线,但是有个特别诡异的问题:

 

    在service里注册这两个广播,在屏幕黑下的时候keylock.disableKeyguard();屏幕亮的时候也同样操作,暂时是好的。

 

可以屏蔽系统的锁屏。但是有时系统锁屏会重新出现。而且一旦出现就不会消失,除非重启之后才会是我的。我打印过日志,

 

在系统的锁屏出来时没有异常,我的服务里还是执行了keylock.disableKeyguard();但是为什么系统锁屏还是出来,这就很

 

奇怪了。而且日志里也没有什么特殊的内容。

 

望遇到过此类问题解决或者没解决的一起讨论,研究出方案。

 

ps:这个bug不好出现,一旦出现就不会消失。

你好,不知道你的问题解决没有,可以告诉我稍微详细一点的代码吗,你在下文粘贴的,我看得不是特别明白。。。。谢谢啦!

http://mylockforandroid.googlecode.com/svn自己检出来看吧

十分感谢!!!!!!!!!

不客气,多交流。

0 请登录后投票
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics