例如,我有一个应用程序将调用联系人并且必须选择其中一个联系人。
但它并没有完全按照我的意愿行事。它向我显示错误 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/