在服务机器人读取用户输入机器人、用户

2023-09-08 09:02:31 作者:沉沦∫空白的心

我想写一个Android应用程序,这将是一个后台服务,将侦听一个特定的手势或按键preSS中,然后触发一个动作。它甚至有可能做这样的事情他们的服务?如果是的话可能有人指导我正确的方向。我已经寻找高和低能能似乎找到了答案。

I want to write an android app that would be a background service that would listen for either a specific gesture or key press in the and then trigger an action. Is it even possible to do such a thing with a service? If so could someone guide me the right direction. I have search high and low can could seem to find an answer.

推荐答案

不是很难看,他们接触,但这种方式倒是只提供位置,而不是时间,不是在跌宕起伏或

not hard to read where they touch, but the touches in this way provide only location, not time, not on ups or downs.

在你的服务

@Override
public void onDestroy() {
    super.onDestroy();
    if (layout != null) {
        ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(layout);
        layout = null;
    }
}
@Override
public void onCreate() {
    super.onCreate();
    layout = new RelativeLayout(this);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                        WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);
    params.setTitle("test");
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(layout, params);
}

和你的接触处理程序,它将不得不像

and for your touch handler, it will have to be as

public boolean gestureHandler(MotionEvent event, boolean eat) {
        if(event.getAction() == MotionEvent.ACTION_OUTSIDE)