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到文件中
最新推荐文章于 2024-09-13 07:37:26 发布
本文介绍如何在Android应用中通过代码读取系统日志,并将日志信息保存到本地文件中,包括实现步骤、权限需求及示例代码。
1418

被折叠的 条评论
为什么被折叠?



