android获得控制台log,打印控制台log

//android手机root,然后打印控制台的log,从控制台log中查找 Finsky的信息过滤,然后找到包名信息。
 
文章出处:https://blog.csdn.net/pangzaifei/article/details/70213731 public static void monitorGooglePlayLogInRoot() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Process process = null;
                DataOutputStream os = null;
                try {
                    // Finsky为google play log输出过滤标签
                    String cmd = "logcat -s Finsky";
                    // 先切换到root进程
                    process = Runtime.getRuntime().exec("su");
                    os = new DataOutputStream(process.getOutputStream());
                    os.writeBytes(cmd + "\n");
                    os.flush();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                    String line = null;
                    while ((line = bufferedReader.readLine()) != null) {
                        if (line.contains("Selecting account") || line.contains("for package")) {
                            String[] split = line.split("for package ");
                            if (split.length == 2) {
                                String logPart = split[1];
                                String pkName = logPart.substring(0, logPart.lastIndexOf('.'));
                                Log.e("fffpzf", "google play 打开了详情页,包名为:" + pkName);
                                // 执行下载逻辑
//                                onEnterDetailPage(pkName);
                            }
                        }
                    }

                } catch (Exception ignored) {
                } finally {
                    try {
                        if (os != null) {
                            os.close();
                        }
                        process.destroy();
                    } catch (Exception e) {
                    }
                }
            }
        }).start();
    }

猜你喜欢

转载自blog.csdn.net/pangzaifei/article/details/79658426
今日推荐