1.手機內做log除錯:
new Thread() {
@Override
public void run() {
Log.d("Environment.getExternalStorageDirectory()", String
.valueOf(Environment.getExternalStorageDirectory()));
// Calendar cal = Calendar.getInstance();
// cal.set(Calendar.MILLISECOND, 0);
// long timestamp = cal.getTimeInMillis();
// 直接格式化輸出現在時間的方法
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date current = new Date();
String dirName = "Demo_upload";
String rootPath = Environment.getExternalStorageDirectory()
+ "/"+dirName+"/";
File file = new File(rootPath);
if (!file.exists()) {
file.mkdirs();
Log.d("upload1","create dirname:"+rootPath);
}
Log.d("upload1","create dirname2:");
File filename = new File(
Environment.getExternalStorageDirectory() + "/"+dirName+"/"
+ sdFormat.format(current) + "_logfile.txt");
try {
filename.createNewFile();
String cmd = "logcat -v time -f " + filename +" upload1:D *:S";
//讓upload1這個tag等極為debug的訊息列出
Log.d("cmd result:", cmd);
Runtime.getRuntime().exec(cmd);
Log.d("cmd final", "");
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
沒有留言:
張貼留言