Вопрос

I am making an app that enables\disables a keyguard but it works only for the first time this activity is called and after that its remains in the state I set for the first time.

  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);

        }
Это было полезно?

Решение

I figured it out myself the solution is: When the application that gets rid of the lockscreen is destroyed the lockscreen comes up again

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());



        }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top