首页 > 解决方案 > ADB 是否有可能与第 3 方 Android AIDL 进行通信?

问题描述

Android 可用于adb shell service call SERVICE与 .aidl 文件通信、传递参数和获取返回值。但是,它属于Android源代码。安装自己编写的非系统应用程序后我可以做同样的事情吗?

例如,我写了一个应用程序,它的包名是com.test.aidl,里面有一个函数。

fun add(x: Int, y: Int): Int {
    return x +y
}

我可以使用 adb 命令,例如在命令提示符下adb shell service call com.test.aidl add i32 1 i32 2获取值吗?3

标签: androidkotlinadbaidl

解决方案


我已经使用仪器解决了这个问题。

亚行指令

adb shell am insrument -e <NAME> <VALUE> <package/runner>

安卓

public class Test extends android.test.InstrumentationTestRunner{
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(arguments);
        value = (String) bundle.get("name");
}

然后使用sendStatus api在 CMD 上打印。


推荐阅读