Android SDK 在程序中输出日志及查看日志
2010-05-26 22:17:00 来源:WEB开发网Log.i(MyAndroid.ACTIVITY_TAG, "Haha , this is a INFO of MyAndroid. ");
Log.w(MyAndroid.ACTIVITY_TAG, "Haha , this is a WARNING of MyAndroid. ");
return true;
}
}
}
package com.zijun;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
public class MyAndroid extends Activity {
protected static final String ACTIVITY_TAG="MyAndroid";
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(new MyView(this));
}
public class MyView extends View {
public MyView(Context c) {
super(c);
}
@Override
protected void onDraw(Canvas canvas) {
}
@Override
public boolean onMotionEvent(MotionEvent event) {
Log.i(MyAndroid.ACTIVITY_TAG, "=============================");
Log.d(MyAndroid.ACTIVITY_TAG, "Haha , this is a DEBUG of MyAndroid. ");
Log.i(MyAndroid.ACTIVITY_TAG, "Haha , this is a INFO of MyAndroid. ");
Log.w(MyAndroid.ACTIVITY_TAG, "Haha , this is a WARNING of MyAndroid. ");
return true;
}
}
}
以上程序运行后, 在命令行执行 adb logcat -s MyAndroid:I
然后在手机模拟器的屏幕上 点击 拖动鼠标 就能看到相应的日志信息.
更多精彩
赞助商链接