need permission in manifest:

<uses-permission android:name="android.permission.READ_LOGS" />

 

try {

Process process = Runtime.getRuntime().exec("logcat -d");

BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream()));

StringBuilder log=new StringBuilder();

String line;

while ((line = bufferedReader.readLine()) != null) {

log.append(line);

}

TextView tv = (TextView)findViewById(R.id.textView1);

tv.setText(log.toString()); }

catch (IOException e) { }

 

public static void saveLogcatToFile(Context context) {

String fileName = "logcat_"+System.currentTimeMillis()+".txt";

File outputFile = new File(context.getExternalCacheDir(),fileName);

@SuppressWarnings("unused")

Process process = Runtime.getRuntime().exec("logcat -f "+outputFile.getAbsolutePath());

}

 

Ref. http://developer.android.com/intl/zh-tw/tools/debugging/debugging-log.html

 

 

 

 

arrow
arrow
    全站熱搜

    小彬彬 發表在 痞客邦 留言(0) 人氣()