For Example I had an application that will invoke contacts and has to select one of the contact.
But its not doing exactly what I want. It is showing me error Unable to find instrumentation info for: ComponentInfo{com.sample/com.sample.ContactsSelectInstrumentation}
Following is my Code.. This is my Activity class
@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);
}
};
And this is my Intrumentation class.
class ContactsFilterInstrumentation extends Instrumentation {
@Override 开发者_StackOverflow中文版
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);
}
}
Can Any help me out. Thanks in Advance.
Directory structure should be:
src
package.x.y.z.test
MainTest.java
CustomInstrumentationRunner.java
Then in the AndroidManifest.xml, set
<manifest package="package.x.y.z" ...
<instrumentation
android:name="package.x.y.z.test.CustomInstrumentationRunner"
Invoke the above package with the command line:
adb shell am instrumentation -w package.x.y.z/package.x.y.z.test.CustomInstrumentationRunner
An Instrumentation implementation is described to the system through an AndroidManifest.xml's <instrumentation>
tag.
I solved this problem by doing the following:
Use a upper-level package name in the manifest:
Implement the test packages one level down: Java file 1:
package com.xxx.yyy.zzz.ptest.onlylogin;
Java file 2:
package com.xxx.yyy.zzz.ptest.register;
Specify the command line like the following:
...
精彩评论