Android Live Wallpaper touch events

陌路散爱 提交于 2019-12-08 01:43:11

问题


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();
    }
}

回答1:


    @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?




回答2:


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.



来源:https://stackoverflow.com/questions/3006916/android-live-wallpaper-touch-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!