我正在使用 react native 制作一个 android 应用程序。该应用程序使用 java/native 代码进行图像处理。
该应用程序有一个图像组件,单击它会调用一个 java 函数,该函数创建一个图像并将其保存到内部存储中,并将 URI 返回给它。(结果图像可能会有所不同)
示例代码是:
FileOutputStream out = null;
try {
out = new FileOutputStream(imgPath);
resultMap.compress(Bitmap.CompressFormat.JPEG, 100, out);
} catch (Exception e) {
finishCallback.invoke(false);
Toast.makeText(getReactApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
return;
} finally {
try {
out.close();
} catch (IOException e) {
finishCallback.invoke(false);
Toast.makeText(getReactApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
return;
}
}
finishCallback.invoke(true,imgPath.toURI().toString());
Run Code Online (Sandbox Code Playgroud)
接收方应更新图像组件以显示保存的图像。
当我第一次运行它时,它工作正常,但是当我再次运行它时,即使存储中的图像已更改,组件也不会更新。
为了更新视图,我需要关闭应用程序并重新启动它,告诉它显示存储中保存的内容,然后显示更改。
接收方看起来像这样:
(JniActivity.fillDoor是负责更新storage中图片的java函数)
onSelectFillImage = (source) => {
JniActivity.fillDoor(
this.state.doorImageSource.uri,
source.uri,
(isDone, picURI) => {
Alert.alert("is done: …Run Code Online (Sandbox Code Playgroud)