Android 屏幕常亮、低电量监听
2019-04-13 15:26发布
生成海报
Android保持屏幕常亮只需在manifest文件注册权限并使用PowerManager进行管理:
import android.os.PowerManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
private PowerManager pm;
private PowerManager.WakeLock wakeLock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pm = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "Wake");
}
@Override
protected void onResume() {
super.onResume();
wakeLock.acquire();//启用
}
@Override
protected void onPause() {
super.onPause();
wakeLock.release();//释放
}
}
Android低电量监听,设置广播的即可。
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮