Android Live Wallpaper touch events

2019-05-28 07:35发布

I've just started with Android, I'm making a simple Live wallpaper. I'm testing it on a 2.1 emulator. The trouble is while it works in the preview screen before you choose "Set Wallpaper" the touch events don't appear to register on the screen once you've selected it as a wallpaper. Do I need to state anything in the manifest about touch events or so to get it to work? Little bit confused why it would work in one and not the other.

public void handleTouchEvent(MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_UP) {
        //add new BulletHole
        int x = (int)event.getX();
        int y = (int)event.getY();
        synchronized(holes) {
            holes.add(new BulletHole(x,y));
        }
    }

    this.pause = false;     
    synchronized(this) {
        notify();
    }
}

2条回答
Summer. ? 凉城
2楼-- · 2019-05-28 08:32
    @Override
    public void onCreate(SurfaceHolder surfaceHolder) {
        super.onCreate(surfaceHolder);

        // By default we don't get touch events, so enable them.
        setTouchEventsEnabled(true);
    }

??? Does this seam to help?

查看更多
唯我独甜
3楼-- · 2019-05-28 08:36

I know that this question is a bit old, but this goes for all those who stumbled on this while googling. Be careful with the setTouchEnabled function - it works perfectly for 2.1 and 2.1, but on all higher versions of Android it crashes the app.

查看更多
登录 后发表回答