2015-09-22 52 views
1

我試圖設置一個動態壁紙,其中一個功能是當用戶點擊屏幕時,他們將被帶到一個特定的鏈接,我注意到牆紙服務引擎的onCommand方法被調用當我點擊屏幕上的應用程序圖標。有什麼辦法可以糾正這個?Android壁紙onCommand打開應用程序

@Override 
    public Bundle onCommand(String action, int x, int y, int z, Bundle extras, boolean resultRequested) { 
     if (action.equals(WallpaperManager.COMMAND_TAP)) { 
      Uri uri = Uri.parse("blalbla"); 
      try { 
       Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(intent); 
      } catch (Exception e) { 
       Log.i("Wopps","i do"); 
      } 
     } 
     return super.onCommand(action, x, y, z, extras, false); 
    } 
+0

這仍是一個問題,它應該只發送空空間水龍頭COMMAND_TAP。我在Android跟蹤器上記錄了問題:https://issuetracker.google.com/issues/68467342 – Flyview

回答

0

所以雙擊解決了這個問題:)......按需是錯誤的計算策略

gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener() { 
     @Override 
     public boolean onDoubleTap(MotionEvent event) { 
      Uri uri = Uri.parse(uri); 
      try { 
       Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(intent); 
      } catch (Exception e) { 
       Log.i("Double tap ", "went wrong"); 
      } 
      return true; 
     } 
    });