super.onStart();
// First start the activity we are instrumenting -- the contacts
// list.
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);
// This is the Activity object that was started, to do with as we want.
Log.i("ContactsSelectInstrumentation", "Started: " + activity);
// Monitor for the expected start activity call.
ActivityMonitor am = addMonitor(IntentFilter.create(
Intent.ACTION_VIEW, Contacts.People.CONTENT_ITEM_TYPE), null, true);
// We are going to enqueue a couple key events to simulate the user
// selecting an item in the list.
sendKeySync(new KeyEvent(
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN));
sendKeySync(new KeyEvent(
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN));
sendKeySync(new KeyEvent(
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
sendKeySync(new KeyEvent(
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
// Was the expected activity started?
if (checkMonitorHit(am, 1)) {
Log.i("ContactsSelectInstrumentation", "Activity started!");
} else {
Log.i("ContactsSelectInstrumentation", "*** ACTIVITY NOT STARTED!");
}
// And we are done!
Log.i("ContactsSelectInstrumentation", "Done!");
finish(Activity.RESULT_OK, null);