【问题标题】:Detect onTouchEvent if user open an app如果用户打开应用程序,则检测 onTouchEvent
【发布时间】:2013-01-27 12:39:03
【问题描述】:

有没有办法了解用户是在主屏幕上单击应用程序的图标还是只是单击桌面?

在开发动态壁纸的过程中,我重写了onTouchEvent 函数

@Override
    public void onTouchEvent(MotionEvent event) {
        int action = event.getAction();
        float currentXPosition = event.getX();
        float currentYPosition = event.getY();
        Log.d(Constants.TAG_DISPLAY, "Action = " + action);
        Log.d(Constants.TAG_DISPLAY, "X = " + currentXPosition + "Y = " + currentYPosition);

        if (action == MotionEvent.ACTION_UP) {
            Log.d(Constants.TAG_DISPLAY, "FIRE Action, drawframe");
            pos[0] = Math.round(currentXPosition) + 150;
            pos[1] = Math.round(currentYPosition) - 50;
            drawFrame(true, true);
        }
        super.onTouchEvent(event);
    }

为了刷新壁纸。但是如果用户正在打开应用程序,我不想刷新它。从事件或超级动作,是否可以确定用户动作?

【问题讨论】:

    标签: android overriding touch-event motionevent


    【解决方案1】:

    我找到了一种解决方法来了解用户是否打开了应用程序。只是打开进程,而不是将后台应用程序置于前台。

    public int getTotalRunningApp(){
        ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
        List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
        return procInfos.size();
    }
    
    
    @Override
    public void onTouchEvent(MotionEvent event) {           
        int runApp = getTotalRunningApp();
        Log.wtf(Constants.TAG_APP, "RunningApp = " + runApp);           
        ...
        super.onTouchEvent(event);
        runApp = getTotalRunningApp();
        Log.wtf(Constants.TAG_APP, "RunningApp = " + runApp);
        ...
    }
    

    通过在真正的super.onTouchEvent 之前和之后调用getTotalRunningApp(),我们可以监控正在运行的应用程序的数量,并了解“一点”用户是否正在点击应用程序或只是移动主屏幕或什么都不做。 它不适用于后台应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多