开发者

program hangs before goToSleep();

开发者 https://www.devze.com 2023-04-08 21:25 出处:网络
Hi i have this program where it uses voice command to unlock the phone. In this VoiceRecog activity, when i detected command is wrong, it will call goToSleep(1000); which locks the device.

Hi i have this program where it uses voice command to unlock the phone.

In this VoiceRecog activity, when i detected command is wrong, it will call goToSleep(1000); which locks the device.

However, the program will hang before it goes to sleep. What could be the problem? What should i put for the int value in the method?

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {

       PowerManager pm = (PowerManager) getSystemService(Context.POWER_S开发者_如何学JAVAERVICE);

       if(command ==right)
           ....
       else
           pm.goToSleep(10);
}

I have tried using

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

devicePolicyManager.lockNow();

but the program still hangs before it locks.


Only app signed as system app can call goToSleep(), not yours. And at least now, I don't see any good way to force the device to sleep.

0

精彩评论

暂无评论...
验证码 换一张
取 消