Skip to content

Commit 07fb89a

Browse files
committed
保存图片回调
1 parent a24612e commit 07fb89a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

android/src/main/java/com/netease/im/RNAppCacheUtilModule.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class RNAppCacheUtilModule extends ReactContextBaseJavaModule {
2323
private final static String NAME = "AppCacheUtil";
2424

2525
private ReactContext reactContext;
26+
2627
public RNAppCacheUtilModule(ReactApplicationContext reactContext) {
2728
super(reactContext);
2829
this.reactContext = reactContext;
@@ -53,18 +54,25 @@ public void onCleanCache(boolean succeeded) {
5354
}
5455
});
5556
}
57+
5658
@ReactMethod
5759
public void saveImageToAlbum(String filePath, final Promise promise) {
5860

5961
File imageFile = new File(filePath);
60-
if(imageFile.exists()){
62+
if (imageFile.exists()) {
6163
try {
62-
MediaStore.Images.Media.insertImage(reactContext.getContentResolver(), imageFile.getAbsolutePath(), "title", "description");
64+
String path = MediaStore.Images.Media.insertImage(reactContext.getContentResolver(), imageFile.getAbsolutePath(), "title", "description");
6365
reactContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + imageFile.getAbsolutePath())));
66+
if (new File(path).exists()) {
67+
promise.resolve("200");
68+
} else {
69+
promise.reject("-1", "");
70+
}
6471
} catch (FileNotFoundException e) {
6572
e.printStackTrace();
6673
}
67-
74+
} else {
75+
promise.reject("-1", "");
6876
}
6977

7078

0 commit comments

Comments
 (0)