Java React本机应用程序不';t从意式浓缩咖啡接收图像
我正在编写在我的React原生应用程序上运行的浓缩咖啡测试。我使用Java React本机应用程序不';t从意式浓缩咖啡接收图像,java,android,android-espresso,Java,Android,Android Espresso,我正在编写在我的React原生应用程序上运行的浓缩咖啡测试。我使用意式浓缩咖啡模拟用户拍照,代码如下: public void takePicture() { Instrumentation.ActivityResult result = createImageCaptureActivityResultStub(); intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(result); cl
意式浓缩咖啡
模拟用户拍照,代码如下:
public void takePicture() {
Instrumentation.ActivityResult result = createImageCaptureActivityResultStub();
intending(hasAction(MediaStore.ACTION_IMAGE_CAPTURE)).respondWith(result);
clickText("Camera");
}
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
// Log exception
System.out.println(e.toString());
return null;
}
}
private Instrumentation.ActivityResult createImageCaptureActivityResultStub() {
// Put the drawable in a bundle.
Bundle bundle = new Bundle();
bundle.putParcelable("data", getBitmapFromURL("https://vignette.wikia.nocookie.net/the-feed-your-pets-community/images/6/69/Banana.png/revision/latest?cb=20180527162222"));
// Create the Intent that will include the bundle.
Intent resultData = new Intent();
resultData.putExtras(bundle);
// Create the ActivityResult with the Intent.
return new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
}
运行时,相机意图被成功截取,但应显示照片的视图仍处于加载状态
在调试过程中,我发现getBitmapFromURL
不是问题所在,因为bundle
包含正确的图像
有人能建议问题出在哪里,或者如何更好地进一步调试吗?使用putSerializable而不是putParcelable。@ViralPatel Hi,使用
putSerializable
我得到了错误的第二个参数类型。找到:“android.graphics.Bitmap”,必需:“java.io.Serializable”
。如果我只是将URL作为字符串传递,我会得到与原始问题相同的结果。在将位图传递给putSerializable
之前,我是否需要对其进行操作?能否向我们展示onActivityResult
和startActivityForResult
代码片段?@ahasbini这是一个react原生项目,因此我没有这些…抱歉,我在开始考虑Java实现时错过了这些。你能分享一下你在React native中用了什么从相机上获取图像吗?您是否正在使用react本机图像选择器
?