在服务机器人读取用户输入 [英] android reading user input in a service

查看:149
本文介绍了在服务机器人读取用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个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)

这篇关于在服务机器人读取用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆