Android 代码实现logcat输出到文件
2015-09-23 16:34
441 查看
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)
关键代码:
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)
相关文章推荐
- Android 项目部署之Nexus私服搭建和应用
- Android studio创建模拟器报错
- Android 应用程序之间内容分享详解(二)
- Android服务的方法回传调用
- Android 应用程序之间内容分享详解(一)
- Android软键盘弹出将底部栏顶上去并不会挤压界面
- Android应用如何支持屏幕多尺寸多分辨率问题
- Android利用Filter过滤数据
- 在Android中查看和管理sqlite数据库
- 解决Android单个dex文件不能超过65536个方法问题
- Android基础入门教程——2.4.8 ListView Item多布局的实现
- android通过USB的MTP模式下,禁止用户在根目录有任何操作(例如删除文件夹)
- Android 自定义过滤搜索框 filterable
- Android SDK 源码关联
- Android webview 退出关闭声音 网页调用javascript
- android.content.res.Resources$NotFoundException: String resource ID #0x1
- android 蓝牙通信(一)
- Android 蓝牙开发(一)Android系统的蓝牙模块简介
- 怎么阅读android官方开发文档
- android学习:用自己的Activity打开图片和网页