1

我正在制作一个启用\禁用键盘保护的应用程序,但它仅在第一次调用此活动时有效,之后它仍保持我第一次设置的状态。

  static boolean k=true;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);  


            if(k)
            {

                Log.d("unlock", "done");
                KeyguardManager  myKeyGuard1 = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
                KeyguardLock myLock1 = myKeyGuard1.newKeyguardLock(null);
                myLock1.disableKeyguard();
                k=false;


                finish();

            }
            else{

                Log.d("lock", "done");
                KeyguardManager  myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
                KeyguardLock myLock = myKeyGuard.newKeyguardLock(null);
                myLock.reenableKeyguard();
                k=true;
                finish();

            }


            setContentView(R.layout.home);

        }
4

1 回答 1

1

我自己想出来的解决方案是:当摆脱锁屏的应用程序被破坏时,锁屏再次出现

if(k==1)
        {


            KeyguardManager  myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
            KeyguardLock myLock = myKeyGuard.newKeyguardLock("tag");
            myLock.disableKeyguard();
            k=0;
            finish();

        }
        else{


            android.os.Process.killProcess(android.os.Process.myPid());



        }
于 2012-07-09T03:27:11.967 回答