Search code examples
androidtouch

android three fingers not detected


I'm building an android game that needs 3 fingers. On my device (Samsung S3 mini, android 4.1.2) works fine, the getPointerCount() return 3, but on an other device (Samsung Core Prime, android 4.4.4), getPointerCount() return always 2, it seems that the function onTouchEvent(MotionEvent e) isn't called on the 3rd touch. Why this? Thanks for help.

I use:

class worldGL extends GLSurfaceView {
    world activity;
    world_r renderer;
    ctrl controller;

    public worldGL(Context context){
        super(context);

        this.renderer = new world_r(context);
        setRenderer(this.renderer);

        this.activity = (world) context;
        this.controller = new ctrl();
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        this.controller.setControllerStatus(e, this.renderer.width, this.renderer.height, this.renderer);

        return true;
    }
}

and:

public void setControllerStatus(MotionEvent e, int width, int height, world_r renderer) {
    int pointerIndex = MotionEventCompat.getActionIndex(e);
    int pointerId = MotionEventCompat.getPointerId(e, pointerIndex);
    int xPos = (int) MotionEventCompat.getX(e, pointerIndex);
    int yPos = (int) MotionEventCompat.getY(e, pointerIndex);

    int maskedAction = MotionEventCompat.getActionMasked(e);

    Log.d("Index", Integer.toString(pointerIndex));
    Log.d("ID", Integer.toString(pointerId));
    Log.d("X", Integer.toString((int) e.getX(pointerIndex)));
    Log.d("Y", Integer.toString((int) e.getY(pointerIndex)));
    Log.d("Count", Integer.toString((int) e.getPointerCount()));

    switch (maskedAction) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN: {
            //code                  
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            //code      
            break;
        }
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP: {
            //code                  
            break;
        }
        case MotionEvent.ACTION_OUTSIDE: {
            break;
        }
    }
}

Solution

  • The android.hardware.touchscreen.multitouch.distinct feature is defined like this in the docs (http://developer.android.com/guide/topics/manifest/uses-feature-element.html):

    The application uses advanced multipoint multitouch capabilities on the device screen, such as for tracking two or more points fully independently. This is a superset of multitouch feature.

    So, assuming you've requested multitouch in your manifest (which you ought to be doing), you cannot rely on the hardware to support more than two touches.

    If three touches is absolutely essential, then you could use android.hardware.touchscreen.multitouch.jazzhand instead which guarantees five touches. Unfortunately there doesn't seem to be a method using the manifest to request 3 or more distinct touches.