Android reads user input to service

I want to write an Android app that will be a background service that will listen for either a specific gesture or a keystroke, and then trigger an action. Is it even possible to perform such a service with the service? If that were the case, then someone could guide me in the right direction. I have a search high and low may seem to find the answer.

+5
source share
2 answers

it’s not difficult to read where they touch, but strokes in this way provide only location, not time, not ups and downs.

at your service

@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 should be like

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

( , , ), , , . -, , , .

, , , .

0

All Articles