Android 的logcat支持直接输出到文件。

关键代码:

Runtime.getRuntime().exec("logcat -f "+ filePath);


我个人习惯是写在application的 oncreate()中。

logcat还支持很多其他参数,具体可以参见官方文档。

http://developer.android.com/tools/debugging/debugging-log.html#startingLogcat


这个方法不需要权限,但是对于其他应用的log,是打不出来的。

这是官方说明:

The change is that third party applications can no longer get the read logs permission, however every app can read the logs containing only the lines they have written, without needing any permission.

Keep in mind that access to the logs has never been part of the SDK, and is still not part of the SDK. If you are relying on it then, even after this change, you run the risk of breaking in the future. (And that is partly why this got lost for documentation, it is not part of the SDK, so there isn't really a place to document it, in fact documenting it would kind-of make it a part of the SDK which we don't want. :p)




更多相关文章

  1. FragmentTabHost使用
  2. Android学习笔记:androidmanifest.xml 高级属性
  3. 2012 年最佳 Android(安卓)应用
  4. Android(安卓)1.5 1.6 2.0 2.1 2.2 2.3 3.0,4.0的区别
  5. Android官方命令深入分析之Device Monitor
  6. 2012 年最佳 Android(安卓)应用
  7. Android常用开源项目
  8. 2012 年最佳 Android(安卓)应用
  9. Android(安卓)uses-feature

随机推荐

  1. Android属性动画ObjectAnimator源码简单
  2. Android嵌入式系统程序开发
  3. Android1.6好使,但是2.1 2.2遇到问题,不好
  4. 《Android(安卓)开发艺术探索》笔记2--IP
  5. android完全退出程序(android退出有多个ac
  6. Android布局属性补遗
  7. Android之selector标签
  8. Android磁盘管理-系统源码分析(1)
  9. layout_alignParentRight android:paddin
  10. android刮奖控件,使用简单。