使用浓缩咖啡我需要从图库中选择一个图像并在ImageView中显示它。
在我的情况下,onActivityResult被调用,但我没有获得显示图像的意图数据。
任何人都可以在这里建议我做错了吗?
以下是我的代码
public void test() {
Matcher<Intent> expectedIntent = AllOf.allOf(IntentMatchers.hasAction(Intent.ACTION_PICK),
IntentMatchers.hasData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
Intents.init();
Intents.intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, getGalleryIntent()));
Espresso.onView(isRoot()).perform(waitFor(1000));
Espresso.onView(withId(R.id.choose)).perform(click());
Intents.intended(expectedIntent);
Intents.release();
}
private Intent getGalleryIntent() {
Bundle bundle = new Bundle();
ArrayList<Parcelable> parcels = new ArrayList<>();
Intent intent = new Intent();
Uri uri1 = Uri.parse("file://storage/emulated/0/DCIM/Camera/IMG_20170427_190140.jpg");
Parcelable parcelable1 = uri1;
parcels.add(parcelable1);
bundle.putParcelableArrayList(Intent.EXTRA_STREAM, parcels);
// Create the Intent that will include the bundle.
intent.putExtras(bundle);
return intent;
}
答案 0 :(得分:0)
您的代码也不适合我,数据为空。 这是做什么的:
private Intent getGalleryIntent() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setData(Uri.parse("content://media/external/images/media/337663"));
return intent;
}