Android 日志收集

来源:互联网 发布:建筑声学设计软件 编辑:程序博客网 时间:2024/05/22 13:30
private void readLog() throws IOException {Log.i("INFO", "上面说请大家吃夜宵  只是我的一种假设,假设我中了500万");//1,创建命令的字符串StringBuffer cmdLine = new StringBuffer();//-d  完整输出日志(不阻塞)  -s过滤cmdLine.append("logcat -d -s INFO");//android系统执行命令Process exec = Runtime.getRuntime().exec(cmdLine.toString());InputStream in = exec.getInputStream();//字节流 转换为子分类BufferedReader br = new BufferedReader(new InputStreamReader(in));String str = null;StringBuffer content = new StringBuffer();while((str=br.readLine())!=null){content.append(str);content.append("\n");}//日志:土司  this---当前类对象---MainActivity//实际开发过程中:保存到本地文件    上传到服务器   第3方框架收集日志信息Toast.makeText(this, content, Toast.LENGTH_LONG).show();}


<uses-permission android:name="android.permission.READ_LOGS"/>