标签:
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();
}
}
标签:
原文地址:http://www.cnblogs.com/bravolove/p/5007636.html