如何在onTouchEvent期间获取logcat日志?

时间:2015-11-16 13:04:58

标签: android

我发现在onTouchEvent期间无法获取logcat日志。另一方面,我至少可以在六个月前做到这一点。 这就是我所做的,我得到了结果日志。

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onTouchEvent(MotionEvent motionEvent) {

    switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.d("", "ACTION_DOWN");
            Log.d("", "EventLocation X:" + motionEvent.getX() + ",Y:" + motionEvent.getY());
            break;
        case MotionEvent.ACTION_UP:
            Log.d("", "ACTION_UP");
            long eventDuration2 = motionEvent.getEventTime() - motionEvent.getDownTime();
            Log.d("", "eventDuration2: " +eventDuration2+" msec");
            Log.d("", "Pressure: " + motionEvent.getPressure());

            break;
        case MotionEvent.ACTION_MOVE:
            Log.d("", "ACTION_MOVE");
            break;
        case MotionEvent.ACTION_CANCEL:
            Log.d("", "ACTION_CANCEL");
            break;
    }

    return false;
}

}

然后,我得到如下日志:

14:58:25.693  ....testtouchevent D/ ACTION_DOWN
14:58:25.693  ....testtouchevent D/ EventLocation X:196.18164,Y:464.0
14:58:25.723  ....testtouchevent D/ ACTION_MOVE
14:58:25.733  ....testtouchevent D/ ACTION_MOVE
14:58:25.753  ....testtouchevent D/ ACTION_MOVE
14:58:25.813  ....testtouchevent D/ ACTION_UP
14:58:25.813  ....testtouchevent D/ eventDuration2: 118 msec
14:58:25.813  ....testtouchevent D/ Pressure: 0.38823533

我认为Android 6.0或Android Studio1.4已经停止了。 这是Android 6.0的变化之一吗?

实际上,可以设置TextView消息而不是Log.d,但这种方式并不是那么好。 无论如何我想知道原因。

截图: When I add a Log.d in the onCreate(), a log comes up.