本文整理汇总了Java中android.app.Instrumentation.ActivityResult方法的典型用法代码示例。如果您正苦于以下问题:Java Instrumentation.ActivityResult方法的具体用法?Java Instrumentation.ActivityResult怎么用?Java Instrumentation.ActivityResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Instrumentation
的用法示例。
在下文中一共展示了Instrumentation.ActivityResult方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pickGalleryPhoto
import android.app.Instrumentation; //导入方法依赖的package包/类
private static void pickGalleryPhoto() throws IOException {
Drawable drawable = getTargetContext().getResources().getDrawable(R.drawable.upc_library);
Bitmap bmp = drawableToBitmap(drawable);
File storageDir =
new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
"Camera");
File image = File.createTempFile("testImage", ".jpg", storageDir);
FileOutputStream out = new FileOutputStream(image);
bmp.compress(CompressFormat.JPEG, 100, out);
// Build a result to return from the Camera app
Intent resultData = new Intent();
resultData.setData(Uri.fromFile(image));
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
// Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
// with the ActivityResult we just created
intending(not(isInternal())).respondWith(result);
intended(not(isInternal()));
}
示例2: addImage
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void addImage() {
Intent resultData = new Intent();
Bitmap icon = BitmapFactory.decodeResource(getInstrumentation().getContext().getResources(),
R.drawable.mock_camera_image);
resultData.putExtra("data", icon);
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
intending(not(isInternal())).respondWith(result);
Espresso.closeSoftKeyboard();
onView(withId(R.id.imageOpacityOverlay)).perform(click());
onView(withId(R.id.imageOpacityOverlay)).check(matches(not(isDisplayed())));
onView(withId(R.id.imageDelete)).perform(click());
onView(withId(R.id.imageOpacityOverlay)).check(matches(isDisplayed()));
}
示例3: createEnvironmentalSensorListScanActivityResultStub
import android.app.Instrumentation; //导入方法依赖的package包/类
private Instrumentation.ActivityResult createEnvironmentalSensorListScanActivityResultStub() {
Intent resultData = new Intent();
resultData.putExtra(EnvironmentalSensorsScanActivity.EXTRA_DEVICE_ADDRESS, TEST_ADDRESS);
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
return result;
}
示例4: createRequestEnableBluetoothResultStub
import android.app.Instrumentation; //导入方法依赖的package包/类
private Instrumentation.ActivityResult createRequestEnableBluetoothResultStub() {
// create a stub that indicates the user did not enable Bluetooth
Intent resultData = new Intent();
Instrumentation.ActivityResult result =
new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, resultData);
return result;
}
示例5: getPhotoIdActivityResult
import android.app.Instrumentation; //导入方法依赖的package包/类
private Instrumentation.ActivityResult getPhotoIdActivityResult() {
Intent resultData = new Intent();
resultData.setData(
Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
activity.getResources().getResourcePackageName(R.raw.test) + '/' +
activity.getResources().getResourceTypeName(R.raw.test) + '/' +
activity.getResources().getResourceEntryName(R.raw.test)) );
return new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
}
示例6: buildOkResult
import android.app.Instrumentation; //导入方法依赖的package包/类
private static Instrumentation.ActivityResult buildOkResult()
{
Intent resultData = new Intent();
return new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
}
示例7: test01ValidQR
import android.app.Instrumentation; //导入方法依赖的package包/类
@Test
public void test01ValidQR() {
onView(withId(R.id.fab)).check(matches(isDisplayed()));
ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.fab),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
2),
isDisplayed()));
Intents.init();
String valid_qr = "otpauth://hotp/testtoken?secret=TXHEXPREOXHFKDRE6BNZJOFKQ5OLDZWC&counter=1&digits=6&issuer=privacyIDEA";
String invalid_qr = "lalalalala";
// Build a result to return from the ZXING app
Intent resultData = new Intent();
resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, valid_qr);
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
// Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
// with the ActivityResult we just created
intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);
/* onView(withId(R.id.fab)).check(matches(isDisplayed()));
onView(withId(R.id.fab)).perform(click());*/
floatingActionButton.perform(click());
// We can also validate that an intent resolving to the "camera" activity has been sent out by our app
intended(hasAction("com.google.zxing.client.android.SCAN"));
sleep(2000);
//onView(withText("Invalid QR Code")).check(matches(isDisplayed()));
//onData(anything("privacyIDEA: testtoken")).check(matches(isDisplayed()));
//onData(withRowString(1, "privacyIDEA: testtoken")).check(matches(isDisplayed()));
onData(anything()).
inAdapterView(withId(R.id.listview)).
atPosition(0).
onChildView(withId(R.id.textViewLabel))
.check(matches(withText(startsWith("privacyIDEA: test"))));
onData(anything()).
inAdapterView(withId(R.id.listview)).
atPosition(0).
onChildView(withId(R.id.textViewToken))
.check(matches(withText(startsWith("163584"))));
//onData(withItem
// delete the token
onData(anything())
.inAdapterView(allOf(withId(R.id.listview),
childAtPosition(
withClassName(is("android.support.constraint.ConstraintLayout")),
1)))
.atPosition(0).perform(longClick());
sleep();
ViewInteraction actionMenuItemView = onView(
allOf(withId(R.id.delete_token2), withContentDescription("Item"),
childAtPosition(
childAtPosition(
withId(R.id.action_mode_bar),
2),
1),
isDisplayed()));
actionMenuItemView.perform(click());
sleep();
ViewInteraction appCompatButton4 = onView(
allOf(withId(android.R.id.button1), withText("YES"),
childAtPosition(
allOf(withClassName(is("android.widget.LinearLayout")),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
3)),
3),
isDisplayed()));
appCompatButton4.perform(click());
Intents.release();
}
示例8: stubEnvironmentalSensorListScanActivityIntent
import android.app.Instrumentation; //导入方法依赖的package包/类
@Before
public void stubEnvironmentalSensorListScanActivityIntent() {
Instrumentation.ActivityResult result = createEnvironmentalSensorListScanActivityResultStub();
intending(allOf(hasComponent(new ComponentName(getTargetContext(),
EnvironmentalSensorsScanActivity.class)),
hasAction(Intent.ACTION_PICK))).respondWith(result);
}
示例9: stubRequestEnableBluetoothIntent
import android.app.Instrumentation; //导入方法依赖的package包/类
@Before
public void stubRequestEnableBluetoothIntent() {
Instrumentation.ActivityResult result = createRequestEnableBluetoothResultStub();
intending(hasComponent(new ComponentName(getTargetContext(),
BluetoothAdapter.ACTION_REQUEST_ENABLE))).respondWith(result);
}