android - Android 中的错误 -- 无法找到 : ComponentInfo 的检测信息

标签 android instrumentation

例如,我有一个应用程序将调用联系人并且必须选择其中一个联系人。 但它并没有完全按照我的意愿行事。它向我显示错误 Unable to find instrumentation info for: ComponentInfo{com.sample/com.sample.ContactsSelectInstrumentation}

以下是我的代码.. 这是我的 Activity 类

 @Override  
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.go);
button.setOnClickListener(mGoListener);
}
private OnClickListener mGoListener = new OnClickListener() {
public void onClick(View v) {
  startInstrumentation(new ComponentName(Test.this,
      ContactsFilterInstrumentation.class), null, null);
}
};

这是我的仪器类。

class ContactsFilterInstrumentation extends Instrumentation {  
@Override    
  public void onCreate(Bundle arguments) {

super.onCreate(arguments);
start(); 

} 

 @Override  

public void onStart() {

super.onStart();

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(getTargetContext(), "com.android.phone.Dialer");
Activity activity = startActivitySync(intent);

Log.i("ContactsFilterInstrumentation", "Started: " + activity);
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_M));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_M));
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A));
waitForIdleSync();
Log.i("ContactsFilterInstrumentation", "Done!");
finish(Activity.RESULT_OK, null);
}
}

任何人都可以帮助我。 提前致谢。

最佳答案

目录结构应该是:

src
  package.x.y.z.test
      MainTest.java
      CustomInstrumentationRunner.java

然后在AndroidManifest.xml中,设置

<manifest package="package.x.y.z" ...

<instrumentation
        android:name="package.x.y.z.test.CustomInstrumentationRunner"

用命令行调用上面的包:

adb shell am instrumentation -w package.x.y.z/package.x.y.z.test.CustomInstrumentationRunner

关于android - Android 中的错误 -- 无法找到 : ComponentInfo 的检测信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608914/

相关文章:

android - 在 TestCase 中启动第二个 Activity (这不是被测 Activity )

java - 如何检测自定义类加载器加载的类?

javascript - 无法在Leaflet map 上绘制从geoJson获取的点

android - 谷歌验证异常 : UNREGISTERED_ON_API_CONSOLE when trying to use Google Sheets API V4

c# - Xamarin:样式 TabWidget

java - 为 Java 代理使用 Byte Buddy

linux - PIN、IMG_AddInstrumentFunction 和 ELF 加载程序

java - 为什么 ASM 不调用我的 `` VisitCode``?

java - 检查服务是否正在从广播接收器内运行

android - Android应用程式在安装时当机