开发者

Android Live Wallpaper Tap Event

When you want to handle a click in your life wallpaper you should use onCommand and wait for the action WallpaperManager.COMMAND_TAP. This is described e.g. in the discussion thread: Android Live Wallpaper Touch Event Hierarchy.

This works fine on my phone, but when i deploy the wallpaper to a tablet (in my case the motorola xoom with android 3.1) COMMAND_TAP is also triggered, 开发者_开发问答when an icon on the home-screen is pressed.

I added a workaround by storing the visible state and delaying the onCommand handling by 1000ms, but I would like a real solution for this problem.


We're having the same issues with Samsung phones, only verified on the Droid Charge SCH-I510 and S2. The S3 does not exhibit the behavior.

Here is the workaround, that Gizmomogwai mentioned in code.

public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested) {
  if (WallpaperManager.COMMAND_TAP.equals(action)) {
    final CustomWallpaperEngine that = this;
    Handler handler = new Handler();

    handler.postDelayed(new Runnable() {
      public void run() {
        if(that.isVisible()) {
          // valid tap command
          // DO STUFF
        } else {
          // Invalid tap command, throw away
        }
      }
    }, 1000);
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜