[英]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时,出现日志。
Android SDK provides a deafult class LogView http://developer.android.com/samples/BasicContactables/src/com.example.android.common.logger/LogView.html which you can use as a view in your application while development. Android SDK提供了一个默认类LogView http://developer.android.com/samples/BasicContactables/src/com.example.android.common.logger/LogView.html ,您可以在开发过程中将其用作应用程序中的视图。
Alternatively take look at 或者看看
https://github.com/jgilfelt/GhostLog https://github.com/jgilfelt/GhostLog
https://play.google.com/store/apps/details?id=org.jtb.alogcat https://play.google.com/store/apps/details?id=org.jtb.alogcat
https://play.google.com/store/apps/details?id=com.nolanlawson.logcat https://play.google.com/store/apps/details?id=com.nolanlawson.logcat
https://github.com/googlesamples/android-BeamLargeFiles/blob/master/Application/src/main/java/com/example/android/common/logger/LogView.java https://github.com/googlesamples/android-BeamLargeFiles/blob/master/Application/src/main/java/com/example/android/common/logger/LogView.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.