Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android reading user input in a service

Tags:

java

android

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.

like image 831
Jim Avatar asked Nov 15 '22 07:11

Jim


1 Answers

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

in 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 will have to be as

public boolean gestureHandler(MotionEvent event, boolean eat) {
        if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
like image 96
Dakun Skye Avatar answered Nov 17 '22 06:11

Dakun Skye