Pix*_*_95 2 logging android save logcat android-logcat
我想把我看到的所有logcat Android Studio(比如这里http://i.imgur.com/IJkGcL4.png)都txt file直接保存在我的设备上.
到目前为止我尝试过的是以下代码onCreate:
File logFile = new File(LogcatDir.getAbsolutePath() + "/log.txt" );
try
{
Process process = Runtime.getRuntime().exec( "logcat -c");
process = Runtime.getRuntime().exec( "logcat -f " + logFile + " *:S MyActivity_BUT_WHAT_TO_PUT_HERE");
}
catch ( IOException e ) {e.printStackTrace();}
Run Code Online (Sandbox Code Playgroud)
并在manifest file:
<uses-permission android:name="android.permission.READ_LOGS" />
Run Code Online (Sandbox Code Playgroud)
我故意做了解析错误之类的
long test = Long.parseLong("z");
Run Code Online (Sandbox Code Playgroud)
但实际上只有这个log.txt:
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
Run Code Online (Sandbox Code Playgroud)
有谁知道,我有什么代码,我得到整个logcat?
这对我有用,它使用以下代码将其保存在主存储器中:
Log.w("before","Logcat save");
// File logFile = new File( + "/log.txt" );
try {
Process process = Runtime.getRuntime().exec("logcat -d");
process = Runtime.getRuntime().exec( "logcat -f " + "/storage/emulated/0/"+"Logging.txt");
}catch(Exception e)
{
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4923 次 |
| 最近记录: |