当前位置: 动力学知识库 > 问答 > 编程问答 >

how to make android torch light stable

问题描述:

i have a problem in my android torch that i just created with android studio

i have finish building this torchlight and i have run and install it in android phone but there is on problem i will like you to help me to solve it out.

  1. if i On the torch light it will On but if the screen of the android phone when off, the torch light Off too. and if i touch the phone screen and the screen light shows the torch will On. why please i need to make the torch light to be On even when the phone is lock and unlock and even when the screen light is On or Off

    . please help me out.

thanks.

网友答案:

Running Apps and services are pause when the phone is locked, but you can acquire WAKE_LOCK key and do your task

PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyWakeLock"); 
wakeLock.acquire();

this will hold the CPU open even if the screen off

分享给朋友:
您可能感兴趣的文章:
随机阅读: