如何启动仪表项目以编程方式使用Android的意图是什么? [英] How to start Instrumentation project programmatically using Android Intent?

查看:186
本文介绍了如何启动仪表项目以编程方式使用Android的意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始测试用例的一种方法是,

one way to start testcase is,

adb shell am instrument 
  -w com.google.vishal.test/android.test.InstrumentationTestRunner 

我要开始这个采用Android code(含意向)

i want to start this using Android code (with intent)

例如,

adb shell am start -n com.google.android.contacts/.ContactsActivity

我们可以运行使用的是Android意图通过下面的方法: -

we can run using Android intent by following method :-

Intent intent = new Intent(com.google.android.contacts, ContactsActivity.class);
startActivity(intent);

但是,如何运行

But, how to run

adb shell am instrument 
  -w com.google.vishal.test/android.test.InstrumentationTestRunner 

通过Android的意图是什么?

by Android intent ?

感谢您的帮助提前: - )

Thanks for your help in advance :-)

推荐答案

命令来启动仪器仪表亚行外壳: -

Command to start instrumentation from adb shell :-

adb shell am instrument -w com.android.vishal.project.test/android.test.InstrumentationTestRunner   

Android的code启动仪器仪表 Android的活动: -

 startInstrumentation(new ComponentName("com.android.vishal.project.test", "android.test.InstrumentationTestRunner"), null, null);

请注意:

另一种方法,

Android的$ C $下启动仪表(的Andr​​oid 2.3到Android 4.1.2)

Android Code for start instrumentation (Android 2.3 to Android 4.1.2)

String str_cmd = "adb shell am instrument -w com.android.vishal.project.test/android.test.InstrumentationTestRunner";
Runtime.getRuntime().exec(str_cmd);

对于Android 4.2它需要许可android.permission.INJECT_EVENTS&放大器;这是只有系统的应用程序允许的。用户应用程序无法使用,因为一些安全原因,此权限。

for Android 4.2 it requires permission "android.permission.INJECT_EVENTS" & which is only allowed by System application. User application can not use this permission because of some security reasons.

所以你不能使用调用Runtime.getRuntime()EXEC(str_cmd)。对于Android 4.2起...

so you can not use Runtime.getRuntime().exec(str_cmd); for Android 4.2 onwards ...

所以现在的工作方法是:

so now working method is :

 startInstrumentation(new ComponentName("com.android.vishal.project.test", "android.test.InstrumentationTestRunner"), null, null);

从活动执行此命令。

execute this command from your Activity.

感谢。

这篇关于如何启动仪表项目以编程方式使用Android的意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆