帖子
帖子
用户
博客
课程
显示全部楼层
26
帖子
1
勋章
571
Y币

[插件开发] 模拟屏幕触摸事件

[复制链接]
发表于 2021-8-26 15:57:10
为什么我在模拟屏幕触摸事件的时候 报错This method can not be called from the main application thread
26
帖子
1
勋章
571
Y币
public void jsmethod_showSleep(UZModuleContext uzModuleContext){
        new TouchThread().run();
        Log.e("touch","设置启动");
    }

    private class TouchThread extends Thread{
        @Override
        public void run() {
            super.run();
            Log.e("touch","启动子线程");
            Instrumentation mInst = new Instrumentation();
            mInst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 100, 100, 0));    //x,y 即是事件的坐标
            mInst.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 100, 100, 0));
        }
    }
26
帖子
1
勋章
571
Y币
我尝试添加子线程 但是还是报错This method can not be called from the main application thread
26
帖子
1
勋章
571
Y币
请会安卓开发的大佬解答一下,我这属实半吊子,本来就是做前端开发的
您需要登录后才可以回帖 登录

本版积分规则