码迷,mamicode.com
首页 > 其他好文 > 详细

读取log日志

时间:2015-11-30 17:59:11      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(this,ReadLogService.class);
startService(i);
}

}

 

 

 

public class ReadLogService extends Service {

@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {

new Thread(){
public void run() {
try {
FileOutputStream fos = new FileOutputStream(new File(getCacheDir(),"xx.log"));
Process process = Runtime.getRuntime().exec("logcat");
InputStream is = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while((line = br.readLine())!=null){
if(line.contains("I/ActivityManager")){//应用程序启动信息
fos.write(line.getBytes());
}
}
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

};
}.start();

super.onCreate();
}


}

读取log日志

标签:

原文地址:http://www.cnblogs.com/bravolove/p/5007636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!