相关疑难解决方法(0)

如何将参数传递给使用adb shell am Instrumentation命令启动的测试功能

我正在开发Android,我正在使用仪器测试手机应用程序.Instrumentation是Android环境来测试应用程序.

为此,我使用带有测试用例名称的am命令.我运行adb,然后输入adb shell,然后在shell中写入am命令.

我希望与这个命令一起提供一个参数.我的意思是我希望将参数传递给am命令启动的测试.

可能吗 ???请帮忙 ?

instrumentation android

25
推荐指数
2
解决办法
3万
查看次数

从额外的命令行启动Android活动

我创建了一个简单的活动,我想从命令行启动并从命令行传递一些值.

但是,如果我尝试做的话

adb shell am start com.example.mike.app/.SimpleActivity --es "Message" "hello!"
Run Code Online (Sandbox Code Playgroud)

然后在activity中接收消息,intent.getExtras()返回null.

活动:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    Log.d(LOGTAG, intent == null ? "Intent is null" : "Intent is not null");
    Log.d(LOGTAG, bundle == null ? "Bundle is null" : "Bundle is not null");
}
Run Code Online (Sandbox Code Playgroud)

结果:

SimpleActivity(12345): Intent is not null
SimpleActivity(12345): Bundle is null
Run Code Online (Sandbox Code Playgroud)

android adb android-intent

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

adb ×1

android-intent ×1

instrumentation ×1