简体   繁体   English

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

[英]How can I get logcat logs during onTouchEvent?

I have found I cannot get logcat logs during onTouchEvent. 我发现在onTouchEvent期间无法获取logcat日志。 On the other hand, I could do it at least six months ago. 另一方面,我至少可以在六个月前做到。 This is what I've done and I got the result logs. 这就是我所做的,我得到了结果日志。

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

}

Then, I got logs as follows: 然后,我得到如下日志:

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

I think Android 6.0 or Android Studio1.4 stopped that. 我认为Android 6.0或Android Studio1.4阻止了这一点。 Is it one of the changes of Android 6.0? 这是Android 6.0的变化之一吗?

In fact, it is possible to set TextView message in stead of Log.d, but that way is not so good. 实际上,可以设置TextView消息代替Log.d,但是这种方法不是很好。 Anyhow I want to know the reason. 无论如何,我想知道原因。

ScreenShot: When I add a Log.d in the onCreate(), a log comes up. 屏幕截图: 当我在onCreate()中添加Log.d时,出现日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM