问答 有没有 adb 获取短信内容或者通过 apk 的 service 获取短信内容?

alex zhao · 2021年11月25日 · 最后由 哲豪 回复于 2021年11月26日 · 2987 次阅读

目前看到获取短信内容的方案是 adb root. 有没有不需要 root 的解决方案

共收到 11 条回复 时间 点赞

读短信数据库

读数据库也得 ROOT

好奇兔一只

短信也是一个 app 把,用 appium 做自动化脚本可以获取把

不需要 root 的

哲豪 回复

具体有落地的实现方案吗?

哲豪 回复

那倒是把命令给出来呀。。

Cursor cursor = null;
            try {
                cursor = instrumentation.getTargetContext().getContentResolver().query(Uri.parse("content://sms")
                        , new String[]{"_id", "address", "body", "date", "read", "type"},
                        null, null, "date desc"); //
                if (cursor != null) {
                    while (cursor.moveToNext()) {
                        String read = cursor.getString(cursor.getColumnIndex("read"));
                        String type = cursor.getString(cursor.getColumnIndex("type"));
                        if (read.equals("0") && type.equals("1")) {
                            // 在这里获取短信信息
                            String body = cursor.getString(cursor.getColumnIndex("body"));

                            Pattern pattern = Pattern.compile("([0-9]{4,6}).*([0-9]{6})");
                            Matcher matcher = pattern.matcher(body);

                            if (!matcher.find()) {
                                pattern = Pattern.compile("([0-9]{4,6})");
                                matcher = pattern.matcher(body);
                                if (matcher.find()) {
                                    verifyCode = matcher.group(1);
                                    break;
                                }
                            } else {
                                verifyCode = matcher.group(1);
                                break;
                            }
                        }
                    }
                }

这个是获取当前收到的未读短信

很久以前好像搞过
一是可以通过监听短信广播,获取短信内容
其二可以通过 accessbilityservice 监听界面所有信息流
两个都不需要 root,不过都不是 adb 层面的 都需要编写 apk

直接看自动化的结果吧

哲豪 回复

还有一种是将 SIM 卡插入到短信猫中,然后自己实现后台接口。目前我司就是用的这两种

需要 登录 後方可回應,如果你還沒有帳號按這裡 注册