here is an example of reading the logs: http://www.helloandroid.com/tutorials/reading-logs-programatically
you could change this to write to a file instead of to a textview.
need permission in manifest:
<uses-permission android:name="android.permission.READ_LOGS" />
Code:
public class LogTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); 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) { } } }
[Android]保存logcat到文件中
最新推荐文章于 2023-07-26 18:28:32 发布