方案一、使用Android唤醒aip 1、加入权限 2、进行初始化 private PowerManager pm;// init powerManager private Context cnt; private v
private PowerManager pm;// init powerManager private Context cnt; private void wakeUpScreen() { if (cnt != null) { pm = (PowerManager) cnt.getSystemService(POWER_SERVICE); mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "target"); // this target for tell OS which app control screen } }
mWakelock.acquire(1000L);
mWakelock.release();
这里需要注意的是acquire和release必须成对使用
常亮方法
推荐使用,此法最为简单,无需修改代码
android:keepScreenOn="true"
只要是控件基本都有这个属性,代码同样也可以设置
在程序中用代码实现。代码如下:
把这段代码加在setContentView(R.layout.main)之前即可,这种方法,安装时,不会提示安装人是否允许使用禁止休眠功能
想要那个界面保持长亮就把这句话添加到那个界面类中,没添加此语句的界面类不会保持长亮。最实用的的方法
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
public class AutoTouch { public int width = 0; public int height = 0; public void autoClickRatio(Activity act, final double ratioX, final double ratioY) { width = act.getWindowManager().getDefaultDisplay().getWidth(); height = act.getWindowManager().getDefaultDisplay().getHeight(); new Thread(new Runnable() { @Override public void run() { // 线程睡眠0.1s try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } // 生成点击坐标 int x = (int) (width * ratioX); int y = (int) (height * ratioY); // 利用ProcessBuilder执行shell命令 String[] order = {"input", "tap", "" + x, "" + y}; try { new ProcessBuilder(order).start(); } catch (IOException e) { e.printStackTrace(); } } }).start(); } public void autoClickPos(final double x, final double y) {// width = act.getWindowManager().getDefaultDisplay().getWidth();// height = act.getWindowManager().getDefaultDisplay().getHeight(); new Thread(new Runnable() { @Override public void run() { // 线程睡眠0.1s try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } // 利用ProcessBuilder执行shell命令 String[] order = {"input", "tap", "" + x, "" + y}; try { new ProcessBuilder(order).start(); } catch (IOException e) { e.printStackTrace(); } } }).start(); }}
使用
初始化对象 private static AutoTouch autoTouch = new AutoTouch();//自动点击屏幕 调用 autoTouch.autoClickPos( 840, 580);
来源地址:https://blog.csdn.net/shi450561200/article/details/130849703
--结束END--
本文标题: Android从熄屏唤醒屏幕
本文链接: https://lsjlt.com/news/395132.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0